Combobox to show different column after selection

MCCDOM

Registered User.
Local time
Today, 08:42
Joined
Oct 30, 2014
Messages
84
Hi There,

I have a combobox that has three columns, one of which is hidden as this contains the primary key. The other two are both visible when you drop down the combobox list which are 'dept code' and 'office'. However when I select an option and the list retracts it only shows one of the columns data in the combobox in this case 'dept code'. What I would like to know please is if there is a way to get the combobox to show 'office' as the selected column or even have both side by side like it is when the combobox expands to give you options. The data for the combobox is pulled through from a query and the order it goes from left to right is 'Primary Key', 'Dept Code' and then 'Office'.

I look forward to your suggestions.

Many Thanks,

Dom
 
Put a label (or textbox) under the combo box.
After user pick dept, put the office in it.
Code:
Sub cboBox_afterupdate()
Label1.caption = cboBox.column(2)    'In vb, columns start w zero
End sub
 
Hi Ranman256,

Thank you for your reply. That would work but I would like to try and keep the form as clean looking as possible. Surely there must be a way to make column 2 show and not column 1? If I think about it column 1 has taken priority over column 0 but is that because its width is set to 0cm?
 
Not really, normally the other columns are displayed to assist with the choice made. So for a list of customer names you might add a postcode or town for instance, to make sure you pick the correct Mr Smith.
If is is only for display elegance purposes you can achieve it with some clever manoeuvring; create a textbox that is the same width as the combo without the selector arrow. Place it directly over the combo control and select bring to front in the arrange window.
In the after update of the combo set the value of the textbox to the column 2 value, and set focus away from the combo. If it doesn't look quite right you can even hide the combo until the text box has focus etc. I would lock the text box from bieng edited to avoid end user confusion.
 
You're already halfway there...your Combobox is based on a Query!

  • Open the Query in Design View
  • Create a New Field by placing this in the 'Field' box of an empty Field, where the Field Name would normally go:

    DisplayData: [Dept Code] & " " & [Office]

  • Make sure that the 'Show' box is checked
  • Select this New Field and then move it to the left, so that your Fields now read, from left to right:
'Primary Key', DisplayData: [Dept Code] & " " & [Office],'Dept Code', 'Office'

Now you need to adjust the Columns in your Combobox, and the easiest way to do this would be to simply delete your original Combobox then recreate it, on the Query, once again making the PK Field invisible (with a 0" width). You could also do the same with the 'Dept Code' and 'Office' Columns, making the dropdown look cleaner, but still having the individual Fields available for use, elsewhere, if need be.

Once a selection is made and you move off of the Combobox, it will display

Dept Code Office.

Linq ;0)>
 
Hi Missinglinq,

Sorry I completely missed your post. Thank you so much though that solution works perfectly.
 

Users who are viewing this thread

Back
Top Bottom