Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

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
0
matt_fennell
Asked:
matt_fennell
  • 4
  • 4
1 Solution
 
N_K_venkatCommented:
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.
0
 
matt_fennellAuthor Commented:
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?
0
 
Éric MoreauSenior .Net ConsultantCommented:
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?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
matt_fennellAuthor Commented:
Have created a query in Access, what is the code to run it from VB?
0
 
Éric MoreauSenior .Net ConsultantCommented:
>>Have created a query in Access, what is the code to run it from VB?

You better keep it in VB! You need to pass parameters to your region field.

But have you tried to run your query exactly like it appears into the message box directly from Access?
0
 
matt_fennellAuthor Commented:
How do you run the query into Access?
0
 
Éric MoreauSenior .Net ConsultantCommented:
You create a new query, switch to SQL mode, paste the string and click the Run button.
0
 
matt_fennellAuthor Commented:
The msgbox brings up the 'select *' line of code
0
 
Éric MoreauSenior .Net ConsultantCommented:
Points to emoreau
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now