I’m have a query that returns the following columns:
Code
LastName
FirstName
I have a combobox where all of this info is displayed in the dropdown. But when I select a row, all I see in the combobox is the Code (its an employee number). What I’d like to do is display:
“[Code] – [LastName], [FirstName]”
as the selected item when a value is selected, and still store just the [Code] in the combobox’s .Value property.
How is this done? I’m used to C#.NET where a dropdown has 2 properties (displayValue and selectedValue).
1. In this method you won’t be able to have the formatting (dash or comma):
Set the column count to 3.
Set the Bound column to 1 (it’s one-based, even though the .Column property is zero-based).
Adjust column widths to a pleasing arrangement.
Set RowSourceType to “Table/Query”.
Set RowSource to your query.
Do not set a Control Source (leave blank–this leaves the .Value unbound from underlying data).
You can do all the above in Design View.
2. This method is more work, but gets exactly what you asked for:
In Design View:
Set column count to 2.
Set Bound Column to 1,
SetColumn Widths to
0";2"(accepts inches or cm, and if you just enter undecorated numbers will read them as inches (or as set in Options(?))).Set RowSourceType to “Value List”.
Do not set a Control Source (leave blank–this leaves the .Value unbound from underlying data).
Write this code:
The semicolon between the
rs!Codeinstances in the string concatenation is what points them into the appropriate columns.