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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL table populating a MS Word multi-column combobox

Status
Not open for further replies.

tbaguio

Programmer
Sep 25, 2000
41
CA

I have a combobox on a MS Word userform called cboCustName which I want populated by a SQL database. I've already successfully created the connection and have populated the combobox with the correct data.

My next problem is this: How do I pull more than one value into the combobox?

I want the ID number of the recordset in the combobox to be the bound column, whereas I would reveal the strCustName value to the user. This is like a basic pulldown in an Access database. Is this possible in Word? I've only seen combobox examples where only one column is used.

Here is my working code as is, without pulling the ID column from the recordset.

<code>
Private Sub UserForm_Initialize()

Dim cn As ADODB.Connection ' define connection string
Dim cmd As New ADODB.Command ' define ADO command string
Dim rsTest As New ADODB.Recordset 'define ADO recordset
Dim strSQLString As String ' SQL command string
Dim strConnection As String ' SQL Connection String

strConnection = connection stuff here
strSQLString = "SELECT * FROM CUSTOMERS"

'Connection
Set cn = New ADODB.Connection
With cn
.ConnectionString = strConnection
End With
cn.Open

Set cmd.ActiveConnection = cn
cmd.CommandText = strSQLString
rsTest.CursorLocation = adUseClient
rsTest.Open cmd, , adOpenStatic, adLockBatchOptimistic

Do While Not (rsTest.EOF)
Dim intCustID As Integer
Dim strCustName As String
intCustID = rsTest!CustomerID
strCustName = rsTest!CustomerName

Me.cboCustName.List = Array(strCustName)

rsTest.MoveNext

Loop

cn.Close

End Sub
</code>

Got any ideas?

Thanks.

&quot;Sleep is the best meditation.&quot; - Dalai Lama
 
Take a look at the AddItem method of the UserForm.ComboBox object

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top