473,378 Members | 1,066 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Searching Multiple Fields using Single Criteria

I am using a multiple filters to search for specific criteria. In one of the filters criteria, I need to use the OR instead of the AND as illustrated below. When insterting the OR it will not recognize the other criteria.
Expand|Select|Wrap|Line Numbers
  1.     If Not IsNull(Me.cboState) Then
  2.         strWhere = strWhere & "([state] = """ & Me.cboState & """) AND "
  3.     End If
  4.  
  5.     If Not IsNull(Me.cboSurvey1) Then
  6.         strWhere = strWhere & "([surveyor_1] = """ & Me.cboSurvey1 & """) or "
  7.     End If
  8.  
  9.     If Not IsNull(Me.cboSurvey1) Then
  10.             strWhere = strWhere & "([surveyor_2] = """ & Me.cboSurvey1 & """) AND "
  11.     End If
  12.  
  13.  
  14.     If Not IsNull(Me.txtstartdate) Then
  15.         strWhere = strWhere & "([Survey_Start] >= " & Format(Me.txtstartdate, conJetDate) & ") AND "
  16.     End If
  17.     If Not IsNull(Me.txtenddate) Then
  18.         strWhere = strWhere & "([Survey_Start] >= " & Format(Me.txtenddate, conJetDate) & ") AND "
  19.     End If
Attached Files
File Type: txt String Code.txt (726 Bytes, 446 views)
Mar 11 '10 #1
3 2293
ADezii
8,834 Expert 8TB
Aren't these two Statements contradictory. If cboSurvey Is Not Null, the first If..End If will be overwritten by the second If...End If. Not only that, the criteria is different in each case based on the same condition.
Expand|Select|Wrap|Line Numbers
  1. If Not IsNull(Me.cboSurvey1) Then
  2.   strWhere = strWhere & "([surveyor_1] = """ & Me.cboSurvey1 & """) or "
  3. End If
  4.  
  5. If Not IsNull(Me.cboSurvey1) Then
  6.   strWhere = strWhere & "([surveyor_2] = """ & Me.cboSurvey1 & """) AND "
  7. End If
Mar 11 '10 #2
NeoPa
32,556 Expert Mod 16PB
Please reread your question and consider updating it so that it makes sense.

Remember, we don't have your project in front of us so the accuracy of your explanation (question) is important. Hence it's so important to phrase it correctly, so that it makes sense.
Mar 11 '10 #3
gershwyn
122 100+
If I'm understand your problem correctly (and that I'm not sure of) I think the OR condition needs to be isolated with parentheses. As it is set up now, if the state and surveyor match we can ignore the date requirements.

Try replacing this code:
Expand|Select|Wrap|Line Numbers
  1. If Not IsNull(Me.cboSurvey1) Then
  2.   strWhere = strWhere & "([surveyor_1] = """ & Me.cboSurvey1 & """) or "
  3. End If
  4.  
  5. If Not IsNull(Me.cboSurvey1) Then
  6.   strWhere = strWhere & "([surveyor_2] = """ & Me.cboSurvey1 & """) AND "
  7. End If
With this:
Expand|Select|Wrap|Line Numbers
  1. If Not IsNull(Me.cboSurvey1) Then
  2.   strWhere = strWhere & "(([surveyor_1] = """ & Me.cboSurvey1 & """) OR "
  3.   strWhere = strWhere & "([surveyor_2] = """ & Me.cboSurvey1 & """)) AND "
  4. End If
As ADezii pointed out, you are testing for the same condition so these do not need to be within separate IF statements. Note that I added an extra set of parentheses so the OR is evaluated by itself.

If this doesn't work, please post the full code that generates the query and shows how it used and describe in what way it isn't working. The more specific you can be, the better.
Mar 12 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Lloyd Stevens | last post by:
Is there a way to peform a query search on a database where you type in a word to be searched across multiple fields? a bit like a search engine if you like. for example if searching a stock...
0
by: Jason | last post by:
I would like to be able to place a command button on a primary (parent) form that opens up a subform. I want to use this subform to search for or limit the recordset of data in the primary form. ...
0
by: Greg Strong | last post by:
Hello All, In the past I've used a combo box with the 'row source' being an Access SQL union query to select "All" or 1 for only 1 criteria in a query. An example is as follows: SELECT 0 As...
5
by: Dan | last post by:
I wonder if anyone has suggestions for reducing the amount of time it would take to search my array using the function that I have written. I want to find a position in the array of an item that...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
6
by: kcddoorman | last post by:
I built a select query filled with fields from multiple tables and queries. I have one field in this particluar query that will filter out a single order number. In the criteria box I put and that...
21
by: JHNielson | last post by:
I have a table that I would like to be able for the users to search/filter. I have multiple fields to search: I built a form, and I would like them to be able to choose form a set of...
5
by: mforema | last post by:
Hi Everyone, I want to search records by typing in multiple keywords. I currently have a search form. It has a combo box, text box, Search command button, and a subform. The combo box lists the...
1
by: Kye | last post by:
It has been a while since using vb an now I have started a project and I am not sure where my mistake is in my code. Basically what I am doing is trying to build a multiple search string with...
0
by: Kassimu | last post by:
Hi guys out there, There is this database Iam creating, I have a table with 40 fields among which there are Date/time, Text, Number, Memo and Yes/No fields and I have created the form bound to that...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.