Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006
    Posts
    12

    Unanswered: Validate a field

    What is the code for validating a field. I just want to make sure all fields are fill, on my form prior to saving. if not I want it to display a message.

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    How many fields are we talking?

    If it isn't too many, you can check each one for IsNull:

    Code:
    If IsNull(MyControl) Then
       'Whatever
    ElseIf IsNull(MyOtherControl) Then
       'Whatever
    End If
    If you have a WHOLE BUNCH of controls and you don't want to do anything specific, like a custom error message for each invalid control or setting focus, then you could put something in the "tag" property for each control to validate and iterate through them in a for loop:

    Code:
    For Each ctl In Me.Controls
       If ctl.tag = validate Then
          If IsNull(ctl) Then
             MsgBox "None for you!"
             Exit Sub
          End If
       End If
    Next ctl
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Aug 2006
    Posts
    12
    OK I have it now, Thanks for your help.

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •