Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Code for searching 2 different field criteria

Posted on 2003-11-12
10
Medium Priority
?
299 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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 60 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
Simple Linear Regression
Starting up a Project

721 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