On 11 Dec 2004 11:32:33 -0800,
te**@i-vibe.com wrote:
Hi Matthias,
Thanks. But, I've done that. It does not print the fields coming from
external sources. We have lots of queries that actually just replicate
tables from Oracle. And using your suggestion does not print the field
names of the query. It was just empty.
ross
Ok, let's do an example:
I'm linking table "dbo.Custom er" from the Northwind database (sample
database on SQL Server) to my MDB, and rename the table as
"tblCustome r". I *cannot* rename the fields in the linked table.
I'm settting up the followeing query, named "qryCustome r":
SELECT tblCustomers.Cu stomerID, tblCustomers.Co mpanyName,
tblCustomers.Ad dress, tblCustomers.Ci ty,
"Phone " & [Phone] & ", Fax " & [Fax] AS Comm,
"Phone " & [Phone] AS Comm2
FROM tblCustomers;
I run the following code:
Sub DumpCust()
Dim db As DAO.Database
Dim qd As DAO.QueryDef
Dim fld As DAO.Field
Dim td As DAO.TableDef
Set db = CurrentDb
Set qd = db.QueryDefs("q ryCustomer")
Debug.Print qd.Name
For Each fld In qd.Fields
Set td = db.TableDefs(fl d.SourceTable)
Debug.Print " Query Table.Field: " & fld.SourceTable & "." &
fld.Name
Debug.Print " Source Table.Field: " & td.SourceTableN ame & "." &
fld.SourceField
Debug.Print
Next
qd.Close
Set qd = Nothing
db.Close
Set db = Nothing
End Sub
I get the result
qryCustomer
Query Table.Field: tblCustomers.Cu stomerID
Source Table.Field: dbo.Customers.C ustomerID
Query Table.Field: tblCustomers.Co mpanyName
Source Table.Field: dbo.Customers.C ompanyName
Query Table.Field: tblCustomers.Ad dress
Source Table.Field: dbo.Customers.A ddress
Query Table.Field: tblCustomers.Ci ty
Source Table.Field: dbo.Customers.C ity
Query Table.Field: tblCustomers.Co mm
Source Table.Field: dbo.Customers.
Query Table.Field: tblCustomers.Co mm2
Source Table.Field: dbo.Customers.P hone
Thus I get all the information about the source table and fields, with
one exception: The query field "Comm" relates to two different fields,
and this is not covered. You would need to parse the field expresssion
only in this case.
HTH
Matthias Kläy
--
www.kcc.ch