Monday 25 June 2012

Ex1: VBA - List the tables using ADO

List the tables using ADO in VBA
Function ShowSchema()
    'Purpose:   List the tables, using ADO.
    Dim cn As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim i As Integer
    
    Set cn = CurrentProject.Connection
    Set rs = cn.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "TABLE"))
'    For i = 0 To rs.Fields.Count - 1
'        Debug.Print rs.Fields(i).Name
'    Next

    Do While Not rs.EOF
        Debug.Print rs.Fields("TABLE_NAME").Value
        rs.MoveNext
    Loop
    rs.Close
    
    Set rs = Nothing
    Set cn = Nothing
End Function

No comments:

Post a Comment