etech0
asked on
Access dropdown filter add choice for "all"
Hi!
I have an Access dropdown box that's based on a distinct list of all records in the query that is the datasource for that form.
I want that dropdown box to serve as a filter on the data that will show up in the form. (It's a continuous form.)
How do I do this?
Also, I'd like one of the choices to be "ALL", and to not filter the data, but to show all records.
How can I accomplish this?
I have an Access dropdown box that's based on a distinct list of all records in the query that is the datasource for that form.
I want that dropdown box to serve as a filter on the data that will show up in the form. (It's a continuous form.)
How do I do this?
Also, I'd like one of the choices to be "ALL", and to not filter the data, but to show all records.
How can I accomplish this?
ASKER
I'm having a hard time understanding your code. Do I need to put both sections in?
Here is what I have so far:
Here is what I have so far:
SELECT DISTINCT CatWebWork2CopywritersQ.Username FROM CatWebWork2CopywritersQ ORDER BY CatWebWork2CopywritersQ.Username;
No ... the 2nd example was just an expanded example showing what 'can be done' - if you ever need more options.
SELECT DISTINCT CatWebWork2CopywritersQ.Us ername
FROM CatWebWork2CopywritersQ
UNION SELECT "<ALL>", "------------"
FROM CatWebWork2CopywritersQ
ORDER BY 2
Note: The orderby 2 means the 2nd column ... shortcut notation.
mx
SELECT DISTINCT CatWebWork2CopywritersQ.Us
FROM CatWebWork2CopywritersQ
UNION SELECT "<ALL>", "------------"
FROM CatWebWork2CopywritersQ
ORDER BY 2
Note: The orderby 2 means the 2nd column ... shortcut notation.
mx
The above is just to test the UNION query ... and confirm it shows the desired results ... 'ALL' s/b first in list.
mx
mx
ASKER
Hi!
I get an error:
"The number of columns in the two selected tables or queries of a union query do not match."
I get an error:
"The number of columns in the two selected tables or queries of a union query do not match."
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great answer - thanks!
You are welcome ...
mx
mx
SELECT DISTINCT CLng(EmpID), 2 FROM tblEmp
UNION SELECT "ALL", 1 FROM tblEMP
ORDER BY 2;
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;
Then, you need to handle the "ALL" case in the Combo box's AfterUpdate event ... to do what ever.
mx