Required fields on form gives Error 2105..

Wayne Cramer

Registered User.
Local time
Yesterday, 23:28
Joined
Aug 10, 2007
Messages
93
I have a form with two required fields. I have used the following code to show a message box and set the focus to the proper field. It works great if a field at a tab stop after the required field is chosen. The problem comes when a user begins a record the goes straight to the create a new issue button without selecting entries for the required fields. Then he gets the message box but if when he hits OK he gets a 2105 message stating that he can't go to the next record. If he clicks End on the error the focus is put on the required field. Is there a way to trap this error and avoid the extra step to get back on track?

Here's the code:

Private Sub Form_BeforeUpdate(Cancel As Integer)
If IsNull(Issue_Generator) Or Issue_Generator = "" Then
MsgBox "You must enter an Issue Generator", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Issue_Generator.SetFocus
Cancel = True
Exit Sub

ElseIf IsNull(Issue_Type) Or Issue_Type = "" Then
MsgBox "You must enter an Issue Type", vbCritical + vbOKOnly + vbDefaultButton1, "Missing Data"
Issue_Type.SetFocus
Cancel = True
Exit Sub

Else
Cancel = False
End If

End Sub
 
Use the forms on error event to trap it and display a meaningful message
 

Users who are viewing this thread

Back
Top Bottom