ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multi Column ComboBox (https://www.excelbanter.com/excel-programming/326373-multi-column-combobox.html)

Steve Roberts

Multi Column ComboBox
 
Is there a way to make a ComboBox show 2 columns and fill them with info
from a database? I have looked at a bunch of examples and have sucessfully
created a 2 column listbox and tried using that as a launching point for a 2
column combo box. I can't seem to get it figured out. Here is the code I
came up with so far.

Thanks in advance for your suggestions.

Steve

Private Sub CommandButton2_Click()

Dim intColumnCount As Integer
Dim conn As ADODB.Connection
Dim rsPlot As ADODB.Recordset

Set conn = New ADODB.Connection

With conn

.Provider = "SQLOLEDB.1"
.ConnectionString = _
"Password=XXXXXX;Persist Security Info=True;User
ID=structural;Initial Catalog=Advantage; Data Source=ACCOUNT"

conn.Open

End With

' Select the data.
Set rsPlot = conn.Execute("SELECT
Advantage.dbo.CLA.claAddressee,Advantage.dbo.CLA.c laCity FROM
Advantage.dbo.CLA Order By Advantage.dbo.CLA.claAddressee")

Do While Not rsPlot.EOF

ComboBox1.List(intColumnCount, 0) = rsPlot!claAddressee
ComboBox1.List(intColumnCount, 1) = rsPlot!claCity

rsPlot.MoveNext

intColumnCount = intColumnCount + 1

Loop


End Sub




All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com