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
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.