Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using Columns in a ComboBox

Status
Not open for further replies.

MrMajik

IS-IT--Management
Apr 2, 2002
267
I am populating a combobox using vb code using the standard .AddItem

Can I add more than one column of data to the combobox using vb code? None of the data is pulled from a table.

Thank you.
 
Answer: yes.

Open up the properties box and go to the "Format" tab.
o Set the Column Count to 2 (or whatever).
o Set the Column Widths to something like: 1";1"
(the above puts two columns, one inch apiece.)
o Set the List Width to 2" (or whatever...). I have a combobox which opens up a 4 column list, so this property can be important.

I think you're done.


When populating the list, you may have to add two items per line you want to see. I don't know how to do it programmatically, but I'm sure it will follow the same rule as it uses for queries and preset value lists. --
Find common answers using Google Groups:

 
This is an example from a VBA script I use:

Me!lstEIR.ColumnWidths = "1 in;2.8 in;1 in;1 in;0 in"

Sometimes I use the "0 in" to hide data in a list to auto populate fields:

Me!MyTextBox = Me!lstEIR.Column(4)
 
In VBA/Access, I don't think you can use "additem". You need to create a string and use it for the recordsource.

If you have a single column then in your recordsource, "item1;item2;item3;item4" each item would be a separate row. However, if your column count is 2, then Item1 and item2 would be column 1 and column 2 of the first row and item3 and item4 would be column 1 and column 2 of the second row.

You can build the string and then in your code
Code:
combobox.rowsource = string
combobox.rowsourcetype = "Value List"
combobox.columncount = 2
combobox.columnwidths = "1 in;2 in"
Now, if you're doing this in Visual Basic, you need to use the combobox in the Microsoft Forms 2.0 Library in order to be able to have multiple columns. The regular combobox doesn't allow multiple columns.
-Coco

[auto]
 
How do you get around the rowsource max chars allowed problem in Access 97, If teh string gets too long it just sticks up an error message??
 
If that's an issue, I'd say switch to a table/query type rowsource instead of a string. Create a table with two fields and use the name of the table as the rowsource.

To add items to the list you would use an SQL statement:

currentdb.execute "insert into table (field1, field2) values (item1, item2);"

To delete all the items from your list:

currentdb.execute "delete * from table"

And to delete a specific item:

currentdb.execute "delete * from table where (item1 = value1) and (item2 = value2)

-Coco

[auto]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top