Verify that fields are filled when adding a reord

  • Thread starter Thread starter Lysy
  • Start date Start date
L

Lysy

Need to check that user entered data in all the required
fields on a form.
Can't do it at a table level as the user has an option of
going into a record at a later time to complete it.
Tried "if" (below)fuction but getting run time errors.
Field: Part_Number is text and Complaint_Complete is check
box.
Private Sub Complaint_Complete_AfterUpdate()
If ((Part_Number = "") And (Complaint_Complete.Value =
true))
Then MsgBox "Missing Data", vbInformation, "NOTE"
End If
End Sub
Thank you much!
 
Use the BeforeUpdate event of the *form*.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg as String

If IsNull(Me.Part_Number) And _
(Me.Complaint_Complete.Value = True) Then
strMsg = "Part numer is blank. Continue anyway?"
If MsgBox(strMsg, vbYesNo+vbDefaultButton2) <> vbYes Then
cancel = True
End If
End If
End Sub
 
-----Original Message-----
Use the BeforeUpdate event of the *form*.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim strMsg as String

If IsNull(Me.Part_Number) And _
(Me.Complaint_Complete.Value = True) Then
strMsg = "Part numer is blank. Continue anyway?"
If MsgBox(strMsg, vbYesNo+vbDefaultButton2) <> vbYes Then
cancel = True
End If
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.




.
 
Need to check that user entered data in all the required
fields on a form.
Can't do it at a table level as the user has an option of
going into a record at a later time to complete it.
Tried "if" (below)fuction but getting run time errors.
Field: Part_Number is text and Complaint_Complete is check
box.
Private Sub Complaint_Complete_AfterUpdate()
If ((Part_Number = "") And (Complaint_Complete.Value =
true))
Then MsgBox "Missing Data", vbInformation, "NOTE"
End If
End Sub
Thank you much!

What errors are you getting?

Part_Number might be NULL, which is NOT equal to "" (or to anything
else). A safer test is

If ((Me![Part_Number] & "" = "") AND (Me!Complaint_Complete = True))
Then <<< all on one line
MsgBox ...
 
Back
Top