IF and ELSE IF

Topham

Registered User.
Local time
Today, 21:47
Joined
Apr 2, 2010
Messages
31
Hello im new to VBA and im trying to get one button to do 2 things depending on a value in a certain field of a form. Please see code below.

If (Forms![Main Booking Form]!CustomerID) = (Forms![Client Data Form]!txtCustomerID) Then

DoCmd.OpenQuery ("ClientNameFill")

Forms![Main Booking Form]!FName = DLookup("FName", "[ClientNameFill]")

DoCmd.Close acQuery, "ClientNameFill", acSaveNo

ElseIf ([Forms]![Main Booking Form]![CustomerID]) = Null Then

DoCmd.OpenQuery "Contacts Query"

Forms![Main Booking Form]!CustomerID = DLookup("CustomerID", "[Contacts Query]")

Forms![Main Booking Form]!FName = DLookup("FName", "[Contacts Query]")

Forms![Main Booking Form]!SName = DLookup("SName", "[Contacts Query]")

End If

Regards,
 
Why are you opening QUERIES for this. There is no need to open them. You can get the information without opening them up using the DLookup.
 
Do you have a question or a description of a problem?
One observation is that nothing ever equals null. To determine if a variable is null, use the IsNull() function.
 

Users who are viewing this thread

Back
Top Bottom