INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Form Field Validation

How do I validate all controls for null values in one statement? by Terpsfan
Posted: 10 Jul 01

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
 

Back to Visual Basic (Microsoft) Databases FAQ Index
Back to Visual Basic (Microsoft) Databases Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close