Need help in looping vba

Sabilah

New member
Local time
Yesterday, 20:45
Joined
Sep 2, 2016
Messages
6
Hi..I need a help on my looping:

In the main form, I have textbox MID=M123456 and CAV=4
In sub form,
a. I have CID and DateTime.
b. I add MCID =Count(MID)

I want to do a looping for CID <= CAV
if >4,msgbox "More than CAV" then undo
if <>4,msgbox "Less than CAV" then MID will lock and not allow to change

Below is my code but not work

Private Sub Form_BeforeUpdate(Cancel As Integer)
Do Until Me.CMID < Forms![Navigation form]![NavigationSubform].[Form]![MCAV]

Me.CAVITY = Forms![Navigation form]![NavigationSubform].[Form]![MCAV]

Me.DATETIME = Now()
DoCmd.Save
Loop
MsgBox "MORE THAN MODEL CAVITY..."
DoCmd.RunCommand acCmdUndo
End Sub
 
Can you not just put a textbox in your subform that counts the records (the same way you would sum the records). The just refer to that textbox.
 
Can you not just put a textbox in your subform that counts the records (the same way you would sum the records). The just refer to that textbox.

Noted and Thanks. But the looping still ng
 
I guess you want to go from record to record in your subform, is that correct, then you need to use Recordsetclone - Google "recordsetclone+loop"
 
I guess you want to go from record to record in your subform, is that correct, then you need to use Recordsetclone - Google "recordsetclone+loop"

Yap...is correct. Thank I will check with Mr google.:)
 
Sorry ..I'm stuck in Recordsetclone.:mad:
Need a help and attached the accdb.
 

Attachments

I'm also write this code. It's work for more than MCav. What I want if Cid is less than MCav, User not allow to update for new Mid.

Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.CMID > Forms![Navigation form]![NavigationSubform].[Form]![MCAV] - 1 Then
MsgBox "MORE THAN MId CAVITY..."
DoCmd.RunCommand acCmdUndo
Else
Me.MCtg = Forms![Navigation form]![NavigationSubform].[Form]![MCtg]
Me.MCAV = Forms![Navigation form]![NavigationSubform].[Form]![MCAV]
Me.DateTime = Now()
DoCmd.Save
End If
End Sub
 
"What I want if Cid is less than MCav, User not allow to update for new Mid"

So in psuedo code
if Cid < Mcav then
Don't update
else
save changes
endif

You have the comparison the other way, no?
 
for more clear, I want to do a looping like sample attached.
case 1 is ok
case 2 is NG because Cid < MCav, user cannot update the Mid.
 

Attachments

  • Untitled.png
    Untitled.png
    15.3 KB · Views: 80

Users who are viewing this thread

Back
Top Bottom