カタログ ActiveConnection プロパティの例 (VB)

ActiveConnection プロパティを有効な開いている接続に設定すると、カタログが "開きます"。 開いたカタログから、そのカタログに含まれるスキーマ オブジェクトにアクセスできます。

' BeginOpenConnectionVB  
Sub Main()  
    On Error GoTo OpenConnectionError  
  
    Dim cnn As New ADODB.Connection  
    Dim cat As New ADOX.Catalog  
  
    cnn.Open "Provider='Microsoft.Jet.OLEDB.4.0';" & _  
        "Data Source= 'Northwind.mdb';"  
    Set cat.ActiveConnection = cnn  
    Debug.Print cat.Tables(0).Type  
  
    'Clean up  
    cnn.Close  
    Set cat = Nothing  
    Set cnn = Nothing  
    Exit Sub  
  
OpenConnectionError:  
  
    Set cat = Nothing  
  
    If Not cnn Is Nothing Then  
        If cnn.State = adStateOpen Then cnn.Close  
    End If  
    Set cnn = Nothing  
  
    If Err <> 0 Then  
        MsgBox Err.Source & "-->" & Err.Description, , "Error"  
    End If  
End Sub  
' EndOpenConnectionVB  

ActiveConnection プロパティを有効な接続ストリングに設定した場合も、カタログが "開きます"。

Attribute VB_Name = "Catalog"  

参照

ActiveConnection プロパティ (ADOX)
Catalog オブジェクト (ADOX)
Table オブジェクト (ADOX)
Tables コレクション (ADOX)
Type プロパティ (テーブル) (ADOX)