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

Open form ONLY if conditions met 1

Status
Not open for further replies.

meliott

Technical User
Sep 28, 2011
2
US
I'm trying to figure out how to write code that will prevent data entry clerks from using the wrong form. Background: The table has an id number which is the primary key [field1]. It also has a field with a pull-down menu for two options (Option 1 and Option 2) [field2] There are two different forms for each option. Both forms are dependent on a query. In both queries, I have the following criteria set for the id number: Like[enter ID number] so that only one record comes up. If a record for user ID 2222 contains the choice of Option 2 for [field 2], I want an error message to be displayed if the form for Option 1 is selected, and I want the form to close.

I believe the code would go in the On Open property field of the form. I think it would be something like (not including syntax):

If [field2] <> "Option 1" for [userID] (number that was entered by user) Then
Private Sub strMessage "You have either chosen the form for Option 1 by mistake, or the option for the student ID that was entered contains the incorrect option. Please choose the correct form or change the option for this student in the first entry form."
(give an OK button that triggers the form to close)
End If

As you can tell, I'm not a VBA programmer, although I manage to muddle through some VBA code. I would greatly appreciate any help. Thanks.
 

If each ID contains an option number, why bother having the user select an option? Just open the correct form based on the data in the table.


Randy
 
Hi Randy, I don't know how to do that.
 
Like[enter ID number]
Have a look here:
faq701-6763

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top