I have a form with several required textboxes/comboboxes. I have the following validation code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
For Each ctl In Me
If ctl.Tag = "*" Then
If IsNull(ctl) Or ctl = "" Then
MsgBox "You must complete the required fields (marked by *) before you can continue.", vbCritical, "Required Field"
ctl.SetFocus
Cancel = True
Exit Sub
End If
End If
Next
Set ctl = Nothing
End Sub
When I click the Close button on the form, the code works fine and the custom error message pops us. However, when I click OK, another access error message pops up: "You can't save this record at this time.... Do you want to close the database object anyway?" When I click NO, an Action Failed message pops up with error number 2950 requiring me to "Stop all Macros".
What can I do to prevent these two access messages from coming up!
Thanks!
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim ctl As Control
For Each ctl In Me
If ctl.Tag = "*" Then
If IsNull(ctl) Or ctl = "" Then
MsgBox "You must complete the required fields (marked by *) before you can continue.", vbCritical, "Required Field"
ctl.SetFocus
Cancel = True
Exit Sub
End If
End If
Next
Set ctl = Nothing
End Sub
When I click the Close button on the form, the code works fine and the custom error message pops us. However, when I click OK, another access error message pops up: "You can't save this record at this time.... Do you want to close the database object anyway?" When I click NO, an Action Failed message pops up with error number 2950 requiring me to "Stop all Macros".
What can I do to prevent these two access messages from coming up!
Thanks!