Applies To Field object.
Description
Return Values
Object appended to | Usage |
Index | Not supported |
QueryDef | Read-only |
Recordset | Read-only |
Relation | Not supported |
TableDef | Read-only |
See Also SourceTableName property.
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
Example (Microsoft Access)
The following example creates a Recordset object by using an SQL statement that creates aliases for fields in two different tables in the database. The example then prints the name of the field, the original table, and the original field.
Sub SourceInfo()
Dim dbs As Database, rst As Recordset, fld As Field
Dim strSQL As String
' Return reference to current database.
Set dbs = CurrentDb
' Construct SQL statement.
strSQL = "SELECT ProductID As ProductCode, " _
& "CategoryName As TypeOfProduct FROM Categories " _
& "INNER JOIN Products ON Categories.CategoryID " _
& " = Products.CategoryID;"
' Open dynaset-type Recordset object.
Set rst = dbs.OpenRecordset(strSQL)
For Each fld In rst.Fields
' Print field name.
Debug.Print "Field Name: "; fld.Name
' Print original table name.
Debug.Print "Source Table: "; fld.SourceTable
' Print original field name.
Debug.Print "Source Field: "; fld.SourceField
Debug.Print
Next fld
rst.Close
Set dbs = Nothing
End Sub