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
Solved

ms access filter query with empty combobox

Posted on 2014-01-23
2
1,857 Views
Last Modified: 2014-01-23
Hi,

I have a query that i run from a command button on a form that exports the results to an excel spreadsheet. On the form I have a combobox (cboFacilityRefID) to filter the results of the query. This works fine when a value is selected in the combobox. However, if no value is selected the query returns no results. What i want to achieve is for all records to be returned when the combobox is empty.

I have tried the following but this doesnt seem to work

IIf(IsNull([Forms]![frmNavMenuForm].[NavMenuSubform].[Form]![Reports_Reports]![cboFacilityRefID]),True,[Forms]![frmNavMenuForm].[NavMenuSubform].[Form]![Reports_Reports]![cboFacilityRefID])

PS the FacilityRefID field in the underlying table in the query will always have a value in it (either 1,2, or 3 at the moment but will increase to 4,5 or 6 in time).

Many thanks
0
Comment
Question by:andrewpiconnect
2 Comments
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39804579
Try something like:

WHERE [yourField] = [Forms]![frmNavMenuForm].[NavMenuSubform].[Form]![Reports_Reports]![cboFacilityRefID]
OR [Forms]![frmNavMenuForm].[NavMenuSubform].[Form]![Reports_Reports]![cboFacilityRefID] & "" = ""

This basically says: limit my results to those records where [yourField] matches the value in the combo box on the form, or all records if the combo box is empty.

You would get the 2nd part of this WHERE clause by putting the reference to the control in the "Field" row of the query design grid, as though it were a computed column (which is what it actually becomes).
0
 

Author Closing Comment

by:andrewpiconnect
ID: 39804638
excellent. it worked a treat!

On the same basis then I am trying to filter the results further using a date range as follows on the [InceptDate] field in the query:

Between [Forms]![frmNavMenuForm].[NavMenuSubform].[Form]![Reports_Reports]![txtStartDate] And [Forms]![frmNavMenuForm].[NavMenuSubform].[Form]![Reports_Reports]![txtEndDate]

The idea is to filter the results between a date range and combobox but also allow the query the return all values when no date range or combobox value is selected (the [InceptDate] field will always have a date it in as its a compulsory field elsewhere in the database.

can i incoorporate both filters in the same query?
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

790 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