Solved

Code for searching 2 different field criteria

Posted on 2003-11-12
10
274 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
  • 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now