title: List databases and tables of a server in VBA
body: <p>I'm trying to list the databases and the tables of a server.</p>
  
  <p>I have tried using <a href="https://docs.microsoft.com/en-us/sql/ado/reference/ado-api/openschema-method" rel="nofollow noreferrer"><code>OpenSchema</code></a> like in <a href="https://www.motobit.com/tips/detpg_listdb/" rel="nofollow noreferrer">this example</a> but it returns null when doing:</p>
  
  <pre><code>Set Recordset1 = Connection.OpenSchema(Schema:=ADODB.SchemaEnum.adSchemaSchemata)
  MsgBox Prompt:=VBA.IsNull(Expression:=Recordset1.Fields.Item(Index:=0))
  </code></pre>
  
  <p>I have some code below that works for a MySQL server but I'm interested in knowing one way that is more standard and not specific to one DBMS.</p>
  
  <pre><code>' Reference:
  ' Microsoft ActiveX Data Objects 6.1 Library
  
  Private Sub Macro()
  
    Dim Connection As ADODB.Connection
    Dim Recordset1 As ADODB.Recordset
    Dim Recordset2 As ADODB.Recordset
  
    Set Connection = New ADODB.Connection
    Connection.ConnectionString = "Driver={MySQL ODBC 5.1 Driver};Server=127.0.0.1;Port=3306"
    Connection.ConnectionTimeout = 0
    Connection.Open UserId:="root", Password:=""
    Set Recordset1 = New ADODB.Recordset
    Recordset1.ActiveConnection = Connection
    Recordset1.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    Recordset1.Source = "SHOW DATABASES"
    Recordset1.Open
    Set Recordset2 = New ADODB.Recordset
    Recordset2.ActiveConnection = Connection
    Recordset2.CursorLocation = ADODB.CursorLocationEnum.adUseClient
    Do While Not Recordset1.EOF
      Connection.Execute "USE " &amp; Recordset1.Fields.Item(Index:="Database").Value
      Recordset2.Source = "SHOW TABLES"
      Recordset2.Open
      Do While Not Recordset2.EOF
        Debug.Print Recordset1.Fields.Item(Index:=0).Value &amp; " - " &amp; Recordset2.Fields.Item(Index:=0).Value
        Recordset2.MoveNext
      Loop
      Recordset2.Close
      Recordset1.MoveNext
    Loop
    Set Recordset2 = Nothing
    Recordset1.Close
    Set Recordset1 = Nothing
    Connection.Close
    Set Connection = Nothing
  
  End Sub
  </code></pre>