Views、Fields コレクションの例 (VB)

次のコードでは、ビューのフィールド情報を取得するための、Command プロパティおよび Recordset オブジェクトの使用方法を示します。

Sub ViewFields()

    Dim cnn As New ADODB.Connection
    Dim rst As New ADODB.Recordset
    Dim fld As ADODB.Field
    Dim cat As New ADOX.Catalog

    ' Open the Connection
    cnn.Open _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=c:\Program Files\Microsoft Office\" & _
        "Office\Samples\Northwind.mdb;"

    ' Open the catalog
    Set cat.ActiveConnection = cnn

    ' Set the Source for the Recordset
    Set rst.Source = cat.Views("AllCustomers").Command

    ' Retrieve Field information
    rst.Fields.Refresh
    For Each fld In rst.Fields
        Debug.Print fld.Name & ":" & fld.Type
    Next

End Sub