Solved

Access 2003: Using Combobox results with ALL for Query Criteria

Posted on 2011-09-07
9
418 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
[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
  • 4
  • 3
  • 2
9 Comments
 
LVL 75
ID: 36497816
" If the user clicks ALL, then the query should ignore that criteria."

What query ?

mx
0
 
LVL 48

Accepted Solution

by:
Dale Fye (Access MVP) earned 250 total points
ID: 36497820
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
ID: 36498134
fyed, I'm not following the WHERE clause.  If the ComboBox returned something other than NULL what is being passed to the criteria?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 250 total points
ID: 36498170
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
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 36498174
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
ID: 36498207
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 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 36498237
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
ID: 36498290
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
ID: 36498422
Thank you guys....Think i'm getting this...on to the next posting!! :)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

707 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