Before event in forms with two codes

prabhus

Registered User.
Local time
Today, 04:35
Joined
Mar 14, 2012
Messages
67
Hi,

I am using the following 2 codes in my forms before update event, Ist code is to warn the user if he dont choose any one of the check box and it will give the msg box only when the user not selected any one of the check box, and i want the second code not to run and display the msg when the 1 st code gives the warning message since the record is not ready to save.

Private Sub Form_BeforeUpdate(Cancel As Integer)
'User to Select the Product before save
'Provide the user with the option to save/undo
'changes made to the record in the form
If Check107 = No And Check138 = No And Check156 = No Then
MsgBox "choose any one of the check box"
Cancel = Yes
End If
If MsgBox("Changes have been made to this record." _
& vbCrLf & vbCrLf & "Do you want to save these changes?" _
, vbYesNo, "Changes Made...") = vbYes Then
DoCmd.Save
Else
DoCmd.RunCommand acCmdUndo
End If

End Sub
 
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
'User to Select the Product before save
'Provide the user with the option to save/undo
'changes made to the record in the form

  If Check107 = No And Check138 = No And Check156 = No Then
       MsgBox "choose any one of the check box"
       Cancel = True
[COLOR=Blue][B]Exit Sub[/B][/COLOR]
  End If

  If MsgBox("Changes have been made to this record." _
       & vbCrLf & vbCrLf & "Do you want to save these changes?" _
       , vbYesNo, "Changes Made...") = vbNo Then
        DoCmd.RunCommand acCmdUndo
  End If
    
End Sub
 
Changes to the current records are saved automatically in Access bound forms when moving to another record of closing the form.

DoCmd.Save is to save design changes.
 

Users who are viewing this thread

Back
Top Bottom