views:

48

answers:

1

I have a question about DBLookupComboBox.

I have a program that has a database I wrote. It has everything, except when I open DBLookupComboBox it must have a row with null value for when user wants to select nothing. But there isn't one. How can I make a null row show up?

+1  A: 

You must either add a row that says 'Nothing' or 'All', which ever suits. The usual solution is a UNION query, which can be used as the RowSource of the combobox. The Union query can be used to add virtual fields.

If the combo comtains only unique values, you can say:

SELECT "Nothing" As Description
FROM ATable
UNION 
SELECT Description
FROM ATable

UNION eliminates duplicates, UNION ALL< does not, so if there are matching rows, you can say:

SELECT DISTINCT "Nothing" As Description
FROM ATable
UNION ALL
SELECT Description
FROM ATable

If you want "Nothing" to sort first, you must juggle a little and use " Nothing", or "-Nothing", but if you have an ID or Key column you can get a nice sort, like so:

SELECT 0 As ID, "Nothing" As Description
FROM ATable
UNION 
SELECT ID, Description
FROM ATable
Remou
When I want to return 1 row, such as in the SELECT for the "All" or "Nothing" choice, I use SELECT TOP 1 on the smallest indexed table in my app (local, if possible). This seems to be more efficient than DISTINCT, but I've never actually tested.
David-W-Fenton
I guess as long as the table chosen is guaranteed to remain for the life of the database. It could get quite confusing if deleting a small table caused wide ranging problems.
Remou
I don't delete tables as once I've implemented the app, the schema stays in place for the life of the app. I would never choose a table that was not part of the main data schema, or on which the user interface depended (such as the tblConfig that I have in the front end of almost all my apps).
David-W-Fenton