I try to populate a list control with data in a recordset but it doesn't work. My be the syntex is wrong as I'm new to VBA. Here is my code
sub form_load
Dim objConn As ADODB.Connection
Dim objRs As ADODB.Recordset
Dim strConString As String
Dim strSQL As String
Set objConn = New ADODB.Connection
Set objRs = New ADODB.Recordset
strConString = "my string is here" 'connect to a spreadsheet
objConn.Open strConString
strSQL = "Select distinct Company FROM [Sheet1$]"
objRs.Open strSQL, objConn, adOpenStatic, adLockOptimistic
List11.RowSourceType = "table/query"
List11.RowSource = objRs 'not sure if this is correct
objRs.Close
objConn.Close
End Sub
When I debug print the objRs recordset, a list of company name is printed. But how do I populate the list to the control.
Thank you very much in advance