Catalog ActiveConnection Property Example (VB)

Microsoft ActiveX Data Objects (ADO)

Catalog ActiveConnection Property Example (VB)

Setting the ActiveConnection property to a valid, open connection "opens" the catalog. From an open catalog, you can access the schema objects contained within that catalog.

Sub OpenConnection()

    Dim cnn As New ADODB.Connection
    Dim cat As New ADOX.Catalog

    cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source= c:\Program Files\Microsoft Office\" & _
        "Office\Samples\Northwind.mdb;"
    Set cat.ActiveConnection = cnn
    Debug.Print cat.Tables(0).Type

End Sub

Setting the ActiveConnection property to a valid connection string also "opens" the catalog.

Sub OpenConnectionWithString()

    Dim cat As New ADOX.Catalog

    cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=c:\Program Files\Microsoft Office\" & _
        "Office\Samples\Northwind.mdb;"
    Debug.Print cat.Tables(0).Type

End Sub