Validation for fields in a record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a form where the user will update information or a record already in
the table. The user access a form and them makes the appropriate updates.
There are three fields that are required to have information in them prior to
closing the form or saving the record. I am limited in my knowledge of vba
coding.
 
Use the Before Update event of the form:

If IsNull(Me.RequiredField1) or Me.RequiredField1 = "" Then
MsgBox "Field 1 Must be filled in"
Cancel = True
Me.RequiredField1.SetFocus
ElseIf IsNull(Me.RequiredField2) or Me.RequiredField2 = "" Then
MsgBox "Field 2 Must be filled in"
Cancel = True
Me.RequiredField1.SetFocus
ElseIf IsNull(Me.RequiredField3) or Me.RequiredField3 = "" Then
MsgBox "Field 3 Must be filled in"
Cancel = True
Me.RequiredField1.SetFocus
End If
 
Hi,

I entered the code and if the field is not filled in, I received the MsgBox
message. When I click 'OK', I receive another message that the "DoMenuItem
action was canceled." How do I remove that second message?
 
See modified code below:

Karen said:
Hi,

I entered the code and if the field is not filled in, I received the MsgBox
message. When I click 'OK', I receive another message that the "DoMenuItem
action was canceled." How do I remove that second message?
 
Back
Top