Discussion Locked

MSAccess combo box display problem

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
My combo box is populated via a Select Query on one table. It finds the data, but displays the two fields only when the focus is on the box, which has dropped down to display the list of choices. When the record is chosen and focus is lost, only onefield is displayed. Column count, column widths and bound column values are set correctly - or the two fields would not display at all.

10 replies

by hmertens

If I understand you correctly this is the proper behavior for the combo-box; it is bound to a single field and can only hold a single value. I presume your select query is of the form:

SELECT fldA, fldB FROM tblX

Two thoughts: if you want to have both fields from the SELECT to be assigned to the bound field then use this query:

SELECT fldA+" "+fldB FROM tblX

or:

SELECT LEFT(fldA+SPACE(5),5) + _
LEFT(fldB+SPACE(5),5) FROM tblX

(presuming in the latter that values in fldA/B are 5-chars or less).

Alternately if you just need the second value from the query to be displayed then add an update event to this combobox and update the value in a accompanying text box beside it...

by bob sellman

Combining the columns, as mentioned in the answer above, is the only way to have both fields displayed.

This works best if your source query table has an ID or code field that is the data stored in your data table. So the column in the data table that is the data source for the combo box would be the one containing the ID. In the drop down box you probably would not display the ID, or, if you do, then you'll have to include it as part of the concatenated columns used for the value displayed in the combo box. I normally hide the IDs except in the situations where they are meaningful outside of the application, such as employee account numbers that are used throughout a company.

by donq

Build a query that combines and/or manages your data into whatever final answer you are after. If the values are always unique a single field Combo box (based on the new quiry) would work and if you need other fields to base your selection on SELECT and display them as well but attach the field with your answer to the Target field.

by whyong

just want to share with you what i normally "do" with the combo box.
when i want to display more than 1 field
i will create another text box, and assign the field 2 value to the text box by writing some code in the combobox onclick event :

textbox = combobox.column1

by developerbunny

I can see how these answers would work, but why does Access display both fields in the combo's dropdown if it won't display both in the combo once it has lost focus? The functionality is fine, because the record's id is being saved for reuse OK, butthe user is baffled to see only one field, having just seen both before choosing the record.

This discussion is closed to new replies.