SourceField, SourceTable Properties Example

This example demonstrates the SourceField and SourceTable properties by opening a Recordset made up of fields from two tables.

Sub SourceFieldX()

    Dim dbsNorthwind As Database
    Dim rstProductCategory As Recordset
    Dim fldLoop As Field
    Dim strSQL As String

    Set dbsNorthwind = OpenDatabase("Northwind.mdb")
    ' Open a Recordset from an SQL statement that uses fields 
    ' from two different tables.
    strSQL = "SELECT ProductID AS ProdID, " & _
        "ProductName AS ProdName, " & _
        "Categories.CategoryID AS CatID, " & _
        "CategoryName AS CatName " & _
        "FROM Categories INNER JOIN Products ON " & _
        "Categories.CategoryID = Products.CategoryID " & _
        "ORDER BY ProductName"
    Set rstProductCategory = _
        dbsNorthwind.OpenRecordset(strSQL)

    Debug.Print "Field - SourceTable - SourceField"
    ' Enumerate Fields collection of Recordset, printing 
    ' name, original table, and original name.
    For Each fldLoop In rstProductCategory.Fields
        Debug.Print "  " & fldLoop.Name & " - " & _
            fldLoop.SourceTable & " - " & fldLoop.SourceField
    Next fldLoop

    rstProductCategory.Close
    dbsNorthwind.Close

End Sub