×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-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!
  • Students Click Here

*Eng-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.

Students Click Here

Jobs

Valiation of Form Data

Valiation of Form Data

Valiation of Form Data

(OP)
I have a form the contains about 30 fields.  Some of these fields are required at all times, and the others are required under some kind of condition.  What I do know is that you can control this in some way by using the validation rule which is listed on the properties window of every field.  What I need to know is how to force the user to make relational entries.  EX.  There is a field called Address, if Address is coded then Zip must also be coded.  As of now the user is only required to enter in Address when one is given so they can skip this field in some cases, but in those cases were the Address is given and must be coded the user is still allowed to skip over the Zip field.  How can I prevent this from happening.  Please Help!  I have tried many types of coding an nothing has helped.

RE: Valiation of Form Data

The following code should solve your problem:
To use this example, copy this sample code to the Declarations portion of a form "UserForm1". Make sure that the form contains the following controls:

**two forms called UserForm1 and UserForm2-
you don't necessarily need UserForm2 but you should omit any reference to it in that case.
** A command button on UserForm1 called CommandButton1-essentially your "OK" button.
** A textbox on UserForm1 called TextBox1-A box for a street address
** A textbox on UserForm1 called TextBox2-A box to enter a zip code.
** A textbox on UserForm1 called TextBox3-Really, it can be any control that is next on the TAB order after TextBox2
** A label on UserForm1 called Label1- Caption should be "Zip Code"
** TAB order should be TextBox1->TextBox2->TextBox3->Commandbutton1


Private Sub CommandButton1_Click()
    If (TextBox1.Value <> "" And TextBox2.Value = "") Then
        HiliteZip
        TextBox2.SetFocus
    Else
        NormalZip
        'Get info from UserForm1 here and go to a new userform
        UserForm2.Show
    End If
End Sub

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If (TextBox1.Value <> "" And TextBox2.Value = "") Then
        Cancel = True
        HiliteZip
    End If
End Sub

Private Sub TextBox3_Enter()
    NormalZip
End Sub

Private Sub HiliteZip()
    Label1.Caption = "*Zip Code required"
    Label1.ForeColor = RGB(255, 0, 0)
    TextBox2.BackColor = RGB(255, 255, 0)
End Sub

Private Sub NormalZip()
    Label1.Caption = "Zip Code"
    Label1.ForeColor = RGB(0, 0, 0)
    TextBox2.BackColor = RGB(255, 255, 255)
End Sub


This code should notify the user that he or she needs to enter a zip code regardless if the user uses the TAB or mouse button or both to move from one field to another.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources