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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Control Validation

Status
Not open for further replies.

Terpsfan

Programmer
Dec 8, 2000
954
US
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top