473,412 Members | 2,262 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,412 software developers and data experts.

Query not returning empty when no parameters are given.

I have a query that has 4 "AND" parameters. The problem I am having is that when I leave all the parameters blank, all records are shown. I need for it to come up empty, so that no records are shown unless parameters are actually given. Here is the SQL for the query:

Expand|Select|Wrap|Line Numbers
  1. SELECT qryPerson.PERSON, qryPerson.Lname, qryPerson.Fname, Contacts.Group_name, Contacts.Subgroup_name 
  2. FROM (qryPerson LEFT JOIN Contacts ON qryPerson.PERSON = Contacts.PERSON) LEFT JOIN Associates ON Contacts.PERSON = Associates.PERSON 
  3. WHERE (((qryPerson.Lname) Like [Forms]![Search Form]![optLname_txt] & "*") AND ((qryPerson.Fname) Like [Forms]![Search Form]![optFname_txt] & "*") AND ((Contacts.Group_name) Like "*" & [Forms]![Search Form]![optAffil_txt] & "*") AND ((Contacts.Subgroup_name) Like "*" & [Forms]![Search Form]![optAffil2_txt] & "*")) 
  4. ORDER BY qryPerson.Lname, qryPerson.Fname;
  5.  
I really need the query to return an empty set if no parameters are met. Any help would be appreciated.
Jan 30 '08 #1
3 1420
FishVal
2,653 Expert 2GB
Hi, there.

Try criteria like the following:
Expand|Select|Wrap|Line Numbers
  1. ..... Like IIf(IsNull(<FormField reference>),"", <FormField reference>) ...
  2.  
Regards,
Fish.
Jan 30 '08 #2
Thank you. I'll try that.
Jan 30 '08 #3
It worked! Thank you!
Jan 30 '08 #4

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

Similar topics

8
by: Rigga | last post by:
Hi, I am new to mysql and need help on how to join tables. I have a database which contains 4 tables, the main table contains information by date order and the other 3 contain data also in date...
3
by: sal cifone | last post by:
Hey, Is there any way to turn off the query parm prompts? I have a report that must be printed for 53 different cities and the vba code loops thru a table and passes the value to a select query....
5
by: Ryan Hubbard | last post by:
Is it possible to get the recordset from an open query window? So you run the query. The window is open. Can vba retrieve this data?
1
by: Ike | last post by:
I have a simple query of joined tables that is failing to give me any rows of data (though, in checking by hand, it certainly should). Essentially, I am trying to return all rows from `ups` that...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
4
by: DeanL | last post by:
Hi Guys, I need some help creating a query that is going to take between 1 and 10 parameters. The parameters are entered on a form into text boxes that may have data or be empty. Is there a...
4
kcdoell
by: kcdoell | last post by:
Hello: What is the best way to stop a report from running if the query is empty? Currently, I have a form that has a command button on it. The user has to make selections from 3 combo boxes on...
36
by: James Harris | last post by:
Initial issue: read in an arbitrary-length piece of text. Perceived issue: handle variable-length data The code below is a suggestion for implementing a variable length buffer that could be used...
1
by: giovannino | last post by:
Dear all, I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !). 1) Given that I'm not a programmer I can't understand why...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.