[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Access 2003: Using Combobox results with ALL for Query Criteria

Posted on 2011-09-07
9
Medium Priority
?
423 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 earned 1000 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 75

Assisted Solution

by:DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 1000 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
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
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

649 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