473,387 Members | 1,374 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,387 software developers and data experts.

Multiple Field Queries

I have been looking for a solution to the following problem:

I have a databases with multiple searchable fields, and what I want to
do is to design a query which will enable me to enter various criteria
to search for, but if I leave some of the prompts blank (or null), then
I still want it to list the data that meets the criteria that was
entered.

I have a form that I want to do this through.

I have seen this problem posted before - and the solution lay in the
MS-Access Solutions Pack, but I have since realized that the postings
were from 1995 and the Solutions Pack was written back when windows 3.1
was the OS.

Does anyone have any suggestions?
Thanks

Nov 13 '05 #1
1 1186
EricV wrote:
I have been looking for a solution to the following problem:

I have a databases with multiple searchable fields, and what I want to
do is to design a query which will enable me to enter various criteria
to search for, but if I leave some of the prompts blank (or null),
then I still want it to list the data that meets the criteria that was
entered.

I have a form that I want to do this through.

I have seen this problem posted before - and the solution lay in the
MS-Access Solutions Pack, but I have since realized that the postings
were from 1995 and the Solutions Pack was written back when windows
3.1 was the OS.

Does anyone have any suggestions?
Thanks


What I do is start with a basic SQL statement...

SELECT * FROM SomeTable Where 1 = 1

I store this in a variable strSQL and then I have code that examines each of the
search TextBoxes on the form thusly...

If IsNull(TextBoxForNumberSearch) = False Then
strSQL = strSQL & " AND SomeNumberField = " & Me.TextBoxForNumberSearch
End If

If IsNull(TextBoxForTextSearch) = False Then
strSQL = strSQL & " AND SomeTextField = '" & Me.TextBoxForTextSearch& "'"
End If

(continue for rest of TextBoxes)

At the end of the code I have a perfectly formatted SQL statement that only uses
the criteria from TextBoxes that actually contained an entry. Blank ones are
simply ignored. This avoids the inefficient use of having lots of " Or
Forms!FormName!ControlName Is Null" clauses in your query.
--
I don't check the Email account attached
to this message. Send instead to...
RBrandt at Hunter dot com
Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steve | last post by:
I am using Access 2000 and I have a DB that is currently running four different queries from some Forms and subforms. These queries each have a date field that are seperate from each other that are...
0
by: MHenry | last post by:
Hi, I know virtually nothing about creating Macros in Access. I would appreciate some help in creating a Macro or Macros that automatically run(s) 14 Queries (three Make Table Queries, and 11...
3
by: tesc | last post by:
I am so aggravated and need any help I can get. I am using Access 2000 and am trying to sort multiple fields in a select query. My query is set up as follows: FIELD 1 FIELD 2 FIELD 3 ...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
5
by: rdemyan via AccessMonster.com | last post by:
I have a need to add another field to all of my tables (over 150). Not data, but an actual field. Can I code this somehow. So the code presumabley would loop through all the tables, open each...
4
by: dreaken667 | last post by:
I have a MySQL database containing 16 tables of data. Each table has a different number of columns and there are few common field names accross tables. I do have one master table with which I connect...
11
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night)...
4
by: mbatestblrock | last post by:
Hello access gurus! I am need of some assitance. I am finally reaching the end or a grueling process. I say grueling, and I am sure its a snap for all of you, which is why I am hoping you all can...
3
by: klbachrodt | last post by:
Hi all - I've been browsing this forum for a while now, looking for help, and finally decided to join and ask my question, since I'm not terribly good at writing SQL queries in Access. Here is my...
13
beacon
by: beacon | last post by:
I'm working on creating a dynamic report that is based on a crosstab query. It's similar to the method described at the following link: http://support.microsoft.com/kb/328320 I've tweaked the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.