>

SourceField, SourceTable Properties

Applies To

Field Object.

This property is not available at design time and is read-only at run time.

Return Values

The return value is a string expression specifying the name of the field or table that is the source of data. The data type is String.

Remarks

For a Field object, use of the SourceField and SourceTable properties depends on the object that contains the Fields collection that the Field object is appended to, as shown in the following table.

Object appended to Usage
 
Index Not supported
QueryDef Read-only

Object appended to Usage
 
Recordset Read-only
Relation Not supported
TableDef Read-only

These properties indicate the original field and table names associated with a Field object. For example, you could use these properties to determine the original source of the data in a query field whose name is unrelated to the name of the field in the underlying table.

See Also

QueryDef Object, SourceTableName Property.

Example

This example creates a Recordset object 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.


Function SourceInfo () As Integer
    Dim dbsNorthwind As Database
    Dim rstEmployCustID As Recordset, fldEnum As Field
    Dim strSelect As String, intStep As Integer
    ' Open database.
    Set dbsNorthwind = _
        DBEngine.Workspaces(0).OpenDatabase("Northwind.mdb")
    ' Construct SQL statement.
    strSelect = "SELECT EmployeeID As EmpID, CustomerID As " & _
        "CustID FROM Employees, Customers;"
    Set rstEmployCustID = dbsNorthwind.OpenRecordset(strSelect)
    For intStep = 0 To rstEmployCustID.Fields.Count - 1
        Set fldEnum = rstEmployCustID.Fields(intStep)
        Debug.Print fldEnum.Name            ' Print field name.
        Debug.Print fldEnum.SourceTable    ' Print original table name.
        Debug.Print fldEnum.SourceField    ' Print original field name.
    Next intStep
    SourceInfo = True
End Function
Example (Microsoft Access)

The following example creates a Recordset object 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 Database object that points to current database.
    Set dbs = CurrentDb
    ' Construct SQL statement.
    strSQL = "SELECT ProductID As ProductCode, " & _
        "CategoryName As TypeOfProduct FROM Products, Categories;"

    Set rst = dbs.OpenRecordset(strSQL)
    For Each fld in rst.Fields
        Debug.Print fld.Name        ' Print field name.
        Debug.Print fld.SourceTable    ' Print original table name.
        Debug.Print fld.SourceField    ' Print original field name.
        Debug.Print
    Next fld
End Sub