Solved

Code for searching 2 different field criteria

Posted on 2003-11-12
10
297 Views
Last Modified: 2010-08-05
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
Comment
Question by:matt_fennell
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
10 Comments
 

Expert Comment

by:N_K_venkat
ID: 9729767
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
 

Author Comment

by:matt_fennell
ID: 9730406
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
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 9730935
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:matt_fennell
ID: 9730964
Have created a query in Access, what is the code to run it from VB?
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 20 total points
ID: 9730986
>>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
 

Author Comment

by:matt_fennell
ID: 9731058
How do you run the query into Access?
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 9731101
You create a new query, switch to SQL mode, paste the string and click the Run button.
0
 

Author Comment

by:matt_fennell
ID: 9731104
The msgbox brings up the 'select *' line of code
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 10316941
Points to emoreau
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question