Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Selecting a record based on two fields

Author  Topic 

RoyPaun
Starting Member

13 Posts

Posted - 2009-07-14 : 15:57:24
I have a form that, when opened, displays all the fields from a 'members table, Surname, firstname, address1, etc. etc. I have a command button that allows me to search the table for a particular person'e record, based on the surname and first name I have previously entered into two unbound text boxes. I can code so that the record is selected and displayed, based on either the surname (in one of the text boxes) or the firstname (in the other text box), but I can not get it to select the record based on both criteria. (Necessary of course for, for example, husband and wife who have the same surname). I have been using the DoCmd.FindRecord, and DoCmd.GoToControl. Advice is greatly appreciated.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-15 : 13:24:04
your query should be something like

SELECT * FROM Table WHERE (@Surname IS NULL OR Surname=@Surname ) AND (@Forename IS NULL OR Forename =@Forename )


and make default value of parameters as NULL
this will ensure the values are returned based on values of parameters passed i.e if 1 parameter only it gives values satisfying that and if 2 it gives values satisfying both
Go to Top of Page
   

- Advertisement -