Solved

Access 2003: Using Combobox results with ALL for Query Criteria

Posted on 2011-09-07
9
412 Views
Last Modified: 2012-06-21
I'm trying to use the attached microsoft "trick" to include ALL as an option in my combobox.  If the user clicks ALL, then the query should ignore that criteria.

Any ideas to accomplish this?

Thanks,
Create a new Query in Design View.
Close the Add Table dialog box.
From the Query menu, select SQL Specific, and then click Union.
Add the following SQL statement to the Query:
SELECT LastName & ", " & FirstName, EmployeeID FROM Employees UNION SELECT '(All)', null FROM Employees
					

Save the Query as EmpUnionAll, and then close the Query.
Open the Employees form in Design view.
Double-click on the ReportsTo combo box to bring up the control properties.
On the Data tab of the Properties box, change the Row Source to the EmpUnionAll query that you created above.
Change the Bound Column property on the Data tab from 1 to 2.
On the Format tab, change the column width from 0 to 2;0.
Open the form in Form view.

Notice that you can now select '(All)' from the combo box list.

Open in new window

0
Comment
Question by:OnsiteSupport
  • 4
  • 3
  • 2
9 Comments
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
" If the user clicks ALL, then the query should ignore that criteria."

What query ?

mx
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 250 total points
Comment Utility
Generally, I prefer to put the Null and EmployeeID as the first column and keep the bound column set to 1 and the column widths set to 0, 2.

Then, your query could read something like:

SELECT Fields from yourTable
WHERE Form!yourForm!cboName IS NULL OR [EmployeeID] = NZ(Form!yourForm!cboName, 0)
0
 

Author Comment

by:OnsiteSupport
Comment Utility
fyed, I'm not following the WHERE clause.  If the ComboBox returned something other than NULL what is being passed to the criteria?
0
 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Access MVP)
DatabaseMX (Joe Anderson - Access MVP) earned 250 total points
Comment Utility
OnsiteSupport:

Try this ... changing to your actual object names:


SELECT Table1.*
FROM Table1
WHERE (((Table1.FIELD1)=IIf([Forms]![YourFormName]![YourComboBoxName]="(ALL)",[FIELD1],[Forms]![YourFormName]![YourComboBoxName])));

mx

0
Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
The bound column (EmployeeID) of the "All" record is NULL, so the value of Form!yourForm!cboName would be NULL if "All" gets selected.

The criteria, when evaluated would read:

WHERE NULL IS NULL OR [EmployeeID] = 0

Since NULL IS NULL would always be TRUE the criteria becomes

WHERE TRUE

Which should return all the records from the SELECT clause.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
I don't see it that way.  Null is not the same as "ALL"  Null is No selection at all (no pun).   ALL is everything.  

mx
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
MX,

If you look at his union query, he set the EmployeeID of the "ALL" record to NULL.  Therefore, the value of the listbox will be NULL, if the user selects "ALL"

Dale
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
ALL examples:

SELECT EmpName, 5 FROM tblEmp
UNION SELECT "<Add New>", 0 FROM tblEMP
UNION SELECT "-----------", 1 FROM tblEMP
UNION SELECT "<Select All>", 2 FROM tblEMP
UNION SELECT "-----------", 3 FROM tblEMP
ORDER BY 2;

==

SELECT EmpName, 2 FROM tblEmp GROUP BY EmpName
UNION SELECT "AUTO", 1 FROM tblEMP
ORDER BY 2;

mx
0
 

Author Closing Comment

by:OnsiteSupport
Comment Utility
Thank you guys....Think i'm getting this...on to the next posting!! :)
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
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, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now