G
Guest
I have a field that can not be set as required at the table level so I have
code at the form level to decide if the field is required, and then force
entry of the required data.
I have placed this code in Form_BeforeUpdate. It works as intended if I use
the record selector buttons to change records.
However, if I close the form using the close button the message box is
displayed but when I click ok the form closes and does not give me a chance
to enter the required data.
How do I stop the form from closing?
Another thing: Why does Access automatically insert ‘(Cancel As Integer)’
after ‘Private Sub Form_BeforeUpdate’?
Thanks,
Seth
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me!cboTestRprtVRangeLow) = False And IsNull(Me!cboTestRprtFreq) =
True Then
MsgBox "You must enter a frequency rating."
Me!cboTestRprtFreq.SetFocus
ElseIf 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 at the form level to decide if the field is required, and then force
entry of the required data.
I have placed this code in Form_BeforeUpdate. It works as intended if I use
the record selector buttons to change records.
However, if I close the form using the close button the message box is
displayed but when I click ok the form closes and does not give me a chance
to enter the required data.
How do I stop the form from closing?
Another thing: Why does Access automatically insert ‘(Cancel As Integer)’
after ‘Private Sub Form_BeforeUpdate’?
Thanks,
Seth
Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Me!cboTestRprtVRangeLow) = False And IsNull(Me!cboTestRprtFreq) =
True Then
MsgBox "You must enter a frequency rating."
Me!cboTestRprtFreq.SetFocus
ElseIf 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