Open a subform based on Name or ID

Val

Registered User.
Local time
Today, 03:41
Joined
Nov 5, 1999
Messages
30
I am trying create a command button that will open a subform based on the criteria in either the name or the ID field. The premise being that the user usually knows 1 or the other but not both.
 
Well, you should do a check to see which value isn't null and then change the recordsource of the subform accordingly, like so...

if not isnull(me!Name) then
me!SubForm_Name.Form.Recordsouce = "SELECT * FROM [Table_or_Query_Name] WHERE Name='" & me!Name) & "'"
elseif not isnull(me!ID) then
me!SubForm_Name.Form.Recordsouce = "SELECT * FROM [Table_or_Query_Name] WHERE ID=" & me!Name)
else
msgbox "Sorry, you must enter either a Name or ID"
end if

That should do it for you. Also, if you want either Name or ID to take precedence in case both are entered then you should put that one first. In my example, if both name and ID are entered, then it will open by name. You can flop the two to have it open by ID. Hope that helps for you.

Doug
 

Users who are viewing this thread

Back
Top Bottom