MS Access: Displaying the table name in a report.

  • Thread starter Thread starter Mario
  • Start date Start date
M

Mario

What expression do I need to use in a textbox so that when
I run the report it displays the name of the table?
Thanks...
 
"Mario" wrote
What expression do I need to use
in a textbox so that when I run the
report it displays the name of the
table?

If, by "the table", you mean that you have a Table as the Record Source of
the Report and you want to print its name, then
where txtX is the name of the Text Box, you can put in the Print event of
the section of the report that contains txtX

Me!txtX = Me.RecordSource

Or, if you prefer, if rptR is the name of the Report, you can put the
following in the Control Source of the Text Box:

= Reports!rptR.RecordSource

But, if you used the Wizard to create the Report, you may actually have an
SQL statement as the RecordSource. If so, that's what will be printed.

Larry Linson
Microsoft Access MVP
 
The record source is a report property that can be displayed with a simple
text box with a control source of:
=[Recordsource]
This will also work with [Filter] and other report properties.
 
Thanks for your responses. I failed to mention that the
report runs a query to display the data from the table.
Therefore, using =recordsource displays the name of the
query instead of the name of the table. Under these
conditions, is there still a way to display the name of
the table? Thanks a lot...

-----Original Message-----
The record source is a report property that can be displayed with a simple
text box with a control source of:
=[Recordsource]
This will also work with [Filter] and other report properties.

--
Duane Hookom
MS Access MVP


Larry Linson said:
"Mario" wrote


If, by "the table", you mean that you have a Table as the Record Source of
the Report and you want to print its name, then
where txtX is the name of the Text Box, you can put in the Print event of
the section of the report that contains txtX

Me!txtX = Me.RecordSource

Or, if you prefer, if rptR is the name of the Report, you can put the
following in the Control Source of the Text Box:

= Reports!rptR.RecordSource

But, if you used the Wizard to create the Report, you may actually have an
SQL statement as the RecordSource. If so, that's what will be printed.

Larry Linson
Microsoft Access MVP


.
 
You could use an expression that finds the word " FROM " in the SQL of the
query. To get the SQL of the query, you would need to use something like
=CurrentDb.QueryDefs("YourQuery").[sql]

--
Duane Hookom
MS Access MVP


Mario said:
Thanks for your responses. I failed to mention that the
report runs a query to display the data from the table.
Therefore, using =recordsource displays the name of the
query instead of the name of the table. Under these
conditions, is there still a way to display the name of
the table? Thanks a lot...

-----Original Message-----
The record source is a report property that can be displayed with a simple
text box with a control source of:
=[Recordsource]
This will also work with [Filter] and other report properties.

--
Duane Hookom
MS Access MVP


Larry Linson said:
"Mario" wrote

What expression do I need to use
in a textbox so that when I run the
report it displays the name of the
table?

If, by "the table", you mean that you have a Table as the Record Source of
the Report and you want to print its name, then
where txtX is the name of the Text Box, you can put in the Print event of
the section of the report that contains txtX

Me!txtX = Me.RecordSource

Or, if you prefer, if rptR is the name of the Report, you can put the
following in the Control Source of the Text Box:

= Reports!rptR.RecordSource

But, if you used the Wizard to create the Report, you may actually have an
SQL statement as the RecordSource. If so, that's what will be printed.

Larry Linson
Microsoft Access MVP


.
 
What is "_the_ table"? A query may have many tables as data sources? If, in
fact, it displays the name of the Query, you'd have to write code that
parsed the .SQL property of that Query to try to find the table you want. I
think it would be possible, maybe even relatively simple, to find the first
reference to a table in most SELECT queries.

But, unless this Report is going to be run using different Queries that
refer to different Tables, the very simplest way is to type in the Table
name in a Label Control. If the same Report _can_ be run against different
Tables, then it's likely time for a careful revisit to your Table Design.

Larry Linson
Microsoft Access MVP


Mario said:
Thanks for your responses. I failed to mention that the
report runs a query to display the data from the table.
Therefore, using =recordsource displays the name of the
query instead of the name of the table. Under these
conditions, is there still a way to display the name of
the table? Thanks a lot...

-----Original Message-----
The record source is a report property that can be displayed with a simple
text box with a control source of:
=[Recordsource]
This will also work with [Filter] and other report properties.

--
Duane Hookom
MS Access MVP


Larry Linson said:
"Mario" wrote

What expression do I need to use
in a textbox so that when I run the
report it displays the name of the
table?

If, by "the table", you mean that you have a Table as the Record Source of
the Report and you want to print its name, then
where txtX is the name of the Text Box, you can put in the Print event of
the section of the report that contains txtX

Me!txtX = Me.RecordSource

Or, if you prefer, if rptR is the name of the Report, you can put the
following in the Control Source of the Text Box:

= Reports!rptR.RecordSource

But, if you used the Wizard to create the Report, you may actually have an
SQL statement as the RecordSource. If so, that's what will be printed.

Larry Linson
Microsoft Access MVP


.
 
Larry, I am only pulling data from one table. It is not a
big database. But I figured I can deal with using
=recordsource and changing the Query name instead. The
Record Source field in the report updates automatically if
I change the name of the query. As you probably know,
Access 2002 does that for you automatically to prevent
queries and reports to be accidentally disconnected from
their source. Hence, for every time I need to show the
name of the query in a report, I just update the name of
the query once and all the places where the name shows in
the report are updated at the same time. The purpose is to
make it simpler for my users to update the database from
time to time so they don't have to deal with report
designs.

Thanks a lot...
Mario...
-----Original Message-----
What is "_the_ table"? A query may have many tables as data sources? If, in
fact, it displays the name of the Query, you'd have to write code that
parsed the .SQL property of that Query to try to find the table you want. I
think it would be possible, maybe even relatively simple, to find the first
reference to a table in most SELECT queries.

But, unless this Report is going to be run using different Queries that
refer to different Tables, the very simplest way is to type in the Table
name in a Label Control. If the same Report _can_ be run against different
Tables, then it's likely time for a careful revisit to your Table Design.

Larry Linson
Microsoft Access MVP


Thanks for your responses. I failed to mention that the
report runs a query to display the data from the table.
Therefore, using =recordsource displays the name of the
query instead of the name of the table. Under these
conditions, is there still a way to display the name of
the table? Thanks a lot...

-----Original Message-----
The record source is a report property that can be displayed with a simple
text box with a control source of:
=[Recordsource]
This will also work with [Filter] and other report properties.

--
Duane Hookom
MS Access MVP


"Mario" wrote

What expression do I need to use
in a textbox so that when I run the
report it displays the name of the
table?

If, by "the table", you mean that you have a Table as the Record Source of
the Report and you want to print its name, then
where txtX is the name of the Text Box, you can put
in
the Print event of
the section of the report that contains txtX

Me!txtX = Me.RecordSource

Or, if you prefer, if rptR is the name of the Report, you can put the
following in the Control Source of the Text Box:

= Reports!rptR.RecordSource

But, if you used the Wizard to create the Report, you may actually have an
SQL statement as the RecordSource. If so, that's what will be printed.

Larry Linson
Microsoft Access MVP




.


.
 
Back
Top