开发者

How can I use a wildcard as an option with a query in a combo box in an Access form?

开发者 https://www.devze.com 2023-03-07 22:09 出处:网络
I\'m making a form in Access to search a database. I want to be able to 开发者_如何学Pythonuse a combo box to let the user know the values that exist in the database. Specifically, something like this

I'm making a form in Access to search a database. I want to be able to 开发者_如何学Pythonuse a combo box to let the user know the values that exist in the database. Specifically, something like this. This works perfectly, however, I'd also like to be able to use the "*" wildcard as an option. In a Value List, it would be as simple as "*";"value1";"value2";etc. but this doesn't seem to work when using a query.

EDIT: I found this. It seems like a different way of solving the problem. I'm still open for suggestions.


Say your combo uses this SELECT statement as it's row source.

SELECT DISTINCT dept_name
FROM Departments
ORDER BY dept_name;

If you want a row with "*" in addition to rows for the unique department names, you can use a UNION query.

SELECT dept_name
FROM Departments
UNION
SELECT "*" AS dept_name
FROM SmallTable
ORDER BY 1;

You don't need the DISTINCT keyword because UNION returns only the unique values from the combined record sets.

You don't actually need to alias the field expression ("*" AS dept_name) in the second SELECT ... the database engine will be happy as long as the data type is compatible with dept_name.

I chose SmallTable in the second SELECT because you only need a table (or a query or subquery) source with a single row. More than one row will not be a deal-killer however, because UNION will discard duplicates.

Anyway that's my best guess as to what you're looking for. If I guessed wrong, clarify what you want and someone will surely give you a better answer.

0

精彩评论

暂无评论...
验证码 换一张
取 消