Solved

ms access filter query with empty combobox

Posted on 2014-01-23
2
1,947 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
[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
2 Comments
 
LVL 48

Accepted Solution

by:
Dale Fye 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 To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

626 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