Report tables names

  • Thread starter Thread starter Jose Lopes
  • Start date Start date
J

Jose Lopes

Hello everyone.

I’m using a report from a query that works with two tables and I need to see
in this report the names of the two tables used. How can I achieve this?
 
If the RecordSource of the report is the name of a query (e.g. Query1), you
could write some code to examine the source query's fields.

Something like this:

Private Sub Report_Open(Cancel As Integer)
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim fld As DAO.Field
Dim strQuery As String

strQuery = Me.RecordSource
Set db = CurrentDb()
Set qdf = db.QueryDefs(strQuery)
For Each fld In qdf.Fields
Debug.Print fld.Name & ": " & fld.SourceTable & "." &
fld.SourceField
Next

Set fld = Nothing
Set qdf = Nothing
Set db = Nothing
End Sub
 
Jose

In a "user-friendly" application, you'd probably want to shield the users
from needing to know anything about the table structure. What will knowing
the tables in a (printed) report allow you or your users to do?

--

Regards

Jeff Boyce
Microsoft Access MVP

Disclaimer: This author may have received products and services mentioned in
this post. Mention and/or description of a product or service herein does
not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
On 9 Sep 2008 it was suggest that should normalize your data.

So I think your database is still not normalized in that your table names
include your data like '2009 Monthly Budgets' or 'January 2010 Expenses.'
 
Back
Top