Val
06-22-2001, 05:52 AM
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.
|
View Full Version : Open a subform based on Name or ID Val 06-22-2001, 05:52 AM 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. D-Fresh 06-22-2001, 06:00 AM 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 |