Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Views and Fields Collections Example (VB)

The following code demonstrates how to use the Command property and the Recordset object to retrieve field information for the view.

' BeginViewFieldsVB
Sub ViewFields()
    On Error GoTo ViewFieldsError
    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='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
    For Each fld In rst.Fields
        Debug.Print fld.Name & ":" & fld.Type

    'Clean up
    Set cat = Nothing
    Set rst = Nothing
    Set cnn = Nothing
    Exit Sub

    If Not cnn Is Nothing Then
        If cnn.State = adStateOpen Then cnn.Close
    End If
    Set cat = Nothing
    Set rst = Nothing
    Set cnn = Nothing
    If Err <> 0 Then
        MsgBox Err.Source & "-->" & Err.Description, , "Error"
    End If
End Sub
' EndViewFieldsVB
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.