Link to home
Start Free TrialLog in
Avatar of matt_fennell
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
Avatar of N_K_venkat
N_K_venkat

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.
Avatar of matt_fennell

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?
Avatar of Éric Moreau
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?
Have created a query in Access, what is the code to run it from VB?
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
The msgbox brings up the 'select *' line of code
Points to emoreau