Link to home
Start Free TrialLog in
Avatar of hindersaliva
hindersalivaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Excel VBA get Access table names with ADO

I got this to work.

Sub GetTableNames()

    'https://www.pcreview.co.uk/threads/get-table-names-from-access-through-vba-in-excel.986969/

    Dim cnn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim lRow As Long
    Dim szConnect As String
    
    Sheet1.UsedRange.Clear
        
    szConnect = "Provider = Microsoft.ACE.OLEDB.12.0;" & _
    "Data Source=C:\VolManAppMan\Database\appman.accdb;"
    
    Set cnn = New ADODB.Connection
    cnn.CursorLocation = adUseClient
    cnn.Open szConnect
    
    Set rs = cnn.OpenSchema( _
    adSchemaTables, _
    Array(Empty, Empty, Empty, "Table"))
    
    With Sheet1
        .Range(.Range("A1"), _
        .Range("A1").Cells(rs.RecordCount)) _
        .Value = Application.Transpose( _
        rs.GetRows(, , "TABLE_NAME"))
    End With
    
    rs.Close
    cnn.Close
    
End Sub

Open in new window


I'd like to get the list into an InCell Dropdown (Data Validation list). For that I need to convert the list to a comma separated string. I can't figure out how. Any help please?
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hindersaliva

ASKER

Thanks Rey!