bgmCoder
bgmCoder

Reputation: 6371

How to Populate a Multi-column Combobox via code?

On my Access form I have an empty combobox with it's Row Source Type set to Table/Query, and Bound Column set to 1.

What I want to do is via code, to fill this combobox with two columns, where it displays the first column to the user and then in code I'll fetch the value from the second column.

My question is, how do I fill the columns? I know how to fill the combobox if the Row/Source is set to Value List - but that's just a flat list; I want two columns here.

I cannot use a separate query/table for the column data because I am generating it dynamically. Basically, I am filling the combobox with a list of edit field control names and their captions. The user selects the caption name from the combobox and then I can fetch the control name.

I just need to know how to add data to columns in the combobox.

So, I figure something like this (I know this is incorrect, but you can see what I am trying to accomplish):

Me.mycombobox.AddItem("column 1 data";"column2 data")

Upvotes: 2

Views: 8886

Answers (1)

Newd
Newd

Reputation: 2185

If you add this into to your event that will trigger the combobox being filled it should shed some light on your question:

Me.Combo0.RowSource = "Row1Column1;Row1Column2;Row2Column1;Row2Column2"

Make sure that your Column Count is set to 2 for this example. Basically you will just build a string formatted like the one in the example filled with the contents that you want to be filled into the combobox. Then just assign it to your Combobox's RowSource.

Basically when you input 6 items as the RowSource:

Item1, Item2, Item3, Item4, Item5, Item6

It will shift based on what you have the Column Count is set to, for example if the column count is set to 3, the above list will turn into:

Item1 Item2 Item3 
Item4 Item5 Item6

If the column count is set to 2 then it will turn into:

Item1 Item2 
Item3 Item4
Item5 Item6

Note: Make sure that you set the Row Source Type to "Value List".

Upvotes: 5

Related Questions