userform combobox rowsource from database

K

Ken

I am trying to set the rowsource for a combo box from a table in a
database, To no avail.

I am using an ADOB connection, open the recordset and try to set the fields
value to the rowSource, but I get the error "invalid property value".
I also don't see how to have a value in multiple columns.

This is my last line of attack.
Me.xtype.RowSource = rst.Fields(0).Value

Can't help but think I am going about this the wrong way.
Any information is greatly appreciated.
 
J

Jeff

Private Sub UserForm_Initialize()
Dim Recordset As ADODB.Recordset
Dim SQL As String

Set Recordset = New Recordset

SQL = "SELECT * FROM returned" '<--- Change to match your table

'The SELECT * will return everything from
'the specified table.

Recordset.Open SQL, connStr, adOpenForwardOnly, adLockReadOnly
'open the recordset

Do Until Recordset.EOF
UserForm1.ComboBox1.AddItem (Recordset.Fields.Item(3))
Recordset.MoveNext
Loop
End Sub
 
J

Jeff

Private Sub UserForm_Initialize()
Dim Recordset As ADODB.Recordset
Dim SQL As String

Set Recordset = New Recordset

SQL = "SELECT * FROM returned" '<--- Change to match your table

'The SELECT * will return everything from
'the specified table.

Recordset.Open SQL, connStr, adOpenForwardOnly, adLockReadOnly
'open the recordset

Do Until Recordset.EOF
With UserForm1.ComboBox1
.ColumnCount = 3 'Change to suit
.AddItem
.List(.ListCount - 1, 0) = Recordset.Fields.Item(3) 'Change to suit
.List(.ListCount - 1, 1) = Recordset.Fields.Item(4) 'Change to suit
'And So on
End With
Recordset.MoveNext
Loop
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top