matt_fennell
asked on
Code for searching 2 different field criteria
Hi. Am trying to search to seperate Access fields from VB but the code I am attempting:
Foo5 = Combo1.Text
Data1.RecordSource = "Select * from Details1 where region = '" & Foo5 & "' and reps ='1'"
Data1.Recordset.MoveFirst
Data1.Refresh
Combo1.Text = "select"
Does the search have to be done using two seperate lines or perhaps my code gramatics is wrong.
Thanks
Foo5 = Combo1.Text
Data1.RecordSource = "Select * from Details1 where region = '" & Foo5 & "' and reps ='1'"
Data1.Recordset.MoveFirst
Data1.Refresh
Combo1.Text = "select"
Does the search have to be done using two seperate lines or perhaps my code gramatics is wrong.
Thanks
U can do search after assigning the recordsource by using data1.recordset.findfirst method.if any record matches for the given criteria then data1.recordset.nomatch will become false else true.
ASKER
I have the search working ok. Recordsource has been assigned etc. Just need the code for a dual search where 2 Access fields are queried.
recordsource = "select * from deatails1 where region="my variable"
What else do I need to include in this code? Do I have to search the other field on a different line of code or the same one?
recordsource = "select * from deatails1 where region="my variable"
What else do I need to include in this code? Do I have to search the other field on a different line of code or the same one?
Try removing the MoveFirst (there is no need for that line there)!
Also, before the Refresh, what do you see if you add this:
msgbox Data1.RecordSource
Have you tried to run this query into Access?
Also, before the Refresh, what do you see if you add this:
msgbox Data1.RecordSource
Have you tried to run this query into Access?
ASKER
Have created a query in Access, what is the code to run it from VB?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How do you run the query into Access?
You create a new query, switch to SQL mode, paste the string and click the Run button.
ASKER
The msgbox brings up the 'select *' line of code
Points to emoreau