Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I validate all controls for null values in one statement?

Form Field Validation

How do I validate all controls for null values in one statement?

by  Terpsfan  Posted    (Edited  )
I have found this procedure to be very helpful for form validation. It loops through the controls on the form to find out if any fields were left blank. For each field that is null, a message is displayed to the user and then focus is returned to that field in order for the user to know exactly which field to enter data on. Performing form validation within the database table will let you know of which field is null but won't set the focus to the field in which the null value exists.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim i As Integer
For i = 0 To Controls.Count - 1
If TypeOf Controls(i) Is TextBox Or _
TypeOf Controls(i) Is ComboBox Then
If IsNull(Controls(i)) Then
MsgBox "No null values allowed"
Controls(i).SetFocus
End
End If
End If
Next i
End Sub
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top