Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ms access filter query with empty combobox

Posted on 2014-01-23
2
Medium Priority
?
2,016 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 49

Accepted Solution

by:
Dale Fye earned 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

927 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