How can you add multi column to a combo box

  • Thread starter Thread starter hin
  • Start date Start date
H

hin

How can you add multi column to a combo box in VB. I can add value
to the first column only using:

combo.AddItem .Fields("TABLE_NAME")

I can I add the second column for this record?
 
There are a couple of things you can do:
1. In the properties of the combo box under the "format"
tab, under "column count", enter the number of columns
you want.

You will also need to specify a column width and increase
the list size.

However, there won't be any data in the new column unless
you specify a field from your data source. For this you
need to go to the "Data" tab and check out the "row
source". Enter the proper information.

2. Another way is to a) create the combo box with the
fields you want to see in it.

b) leave the combo box for a moment and go create a small
query that brings in the fields you want to see in the
combo box.

c) go back to the combo box and to its properties. In
the "Data" tab, "row source", get the query. You can
then follow the above steps in scenario 1 to add columns,
show or hide columns, increase the size of the list, etc.

Hope this helps.
 
I can not create a query or enter the information in the design view.
The reason is because my I'm trying to get the description of Tables
in my database. Here's how it look like

Set cnnDB = New ADODB.Connection

' Open the Connection object.
With cnnDB
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open strDBPath
End With

' Open the tables schema Recordset object.
Set rstList = cnnDB.OpenSchema(adSchemaTables)

' Loop through the recordset and print the names
' and types in the Immediate pane.

With rstList
Do While Not .EOF
If .Fields("TABLE_TYPE") <> "VIEW" And .Fields("TABLE_TYPE")
= "TABLE" Then
cboFrom.AddItem .Fields("TABLE_NAME")
cboFrom.AddItem .Fields("DESCRIPTION")
End If
.MoveNext
Loop
End With
 
From the help file:

"For multiple-column lists, use semicolons to delimit the strings for each
column (for example, "1010;red;large" for a three-column list)"

So, in your situation, something like .AddItem .Fields("TABLE_NAME").Value &
";" & .Fields("DESCRIPTION").Value should do it.

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
Back
Top