SourceFieldName, SourceTableName Properties Example

The example creates a Dynaset object in a data control using an SQL statement that creates aliases for fields in two different tables.  The example then prints the name of the field, the name of the SourceTable, and the name of the SourceField in the Debug window.

Sub PrintSourceInfo ()
  Dim MYSQL, I
  Data1.DatabaseName = "BIBLIO.MDB"
  ' Construct the SQL statement.
  MYSQL = "SELECT PubID As PID, Au_ID As AID"
  MYSQL = MYSQL & " FROM Publishers, Authors"  ' Set the RecordSource property.
  Data1.RecordSource = MYSQL
  Data1.Refresh
  For I = 0 To Data1.Recordset.Fields.Count - 1
    ' Print field name.
    Debug.Print Data1.Recordset.Fields(I).Name
    ' Print source table.
    Debug.Print, Data1.Recordset.Fields(I).SourceTableName,     
    ' Print source field.
    Debug.Print Data1.Recordset.Fields(I).SourceFieldName
  Next I
End Sub