Skip to content
Advertisement

Populate listbox from access file

I have found a piece of code that enables me to list or populate listbox based on access database

When trying that I encountered an error Type data mismatch in criteria expression at this line rst.Open strSQL, cnn, adOpenKeyset, adLockOptimistic, adCmdText

Advertisement

Answer

Your table got a field related to a secondary table (let’s say it’s called tblGender). If the primary Key field in that table is numeric, then datatype of field ActorGenderId in table tblActor is numeric, even if you see a text.

This happens because relations are caused by primary key fields. But in the dropdown list, you can customize and hide the first column (bound column), and see secondary fields (gender in this case).

So that explains why it works if you use:

But you can modify your query, join both tables (tblActor and tblGender) and bring the real text field of gender, so you can specify a text criteria instead of a number.

Something like this should work for you:

Access and Excel got the same feature: what we see is not always the real value. This case is a perfect example of it.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement