• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 314
  • 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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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