Results 1 to 8 of 8

Thread: Use recordset to populate list control

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Use recordset to populate list control

    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
    Last edited by dhartford; 09-25-2008 at 04:57 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •