Retrieve the query name for a report (1 Viewer)

path479

Registered User.
Local time
Today, 21:39
Joined
Jan 4, 2016
Messages
22
Is it possible to retrieve the query name for a report?

I am trying to create a button in a report and when the button is click, it would provide the name of the query that is behind the report (i.e. the query that is record source for the report).

How do I go about in achieving this?

I tried the following in the code for the button but it doesn't work

Dim qry_name as string
qry_name = Report.RecordSource
Msgbox qyr_name
 

Cronk

Registered User.
Local time
Today, 21:39
Joined
Jul 4, 2013
Messages
2,771
Firstly, if you are posting a question with the statement
"but it doesn't work",
it would be helpful to have a bit more detail about what happens or what error you get.

If the report is in print preview mode, you can put a button on a form with the code

msgbox "Report source is " & reports!YourReportName.recordsource
 

path479

Registered User.
Local time
Today, 21:39
Joined
Jan 4, 2016
Messages
22
Firstly, if you are posting a question with the statement
"but it doesn't work",
it would be helpful to have a bit more detail about what happens or what error you get.

If the report is in print preview mode, you can put a button on a form with the code

msgbox "Report source is " & reports!YourReportName.recordsource

Hi Cronk. Thank you for your advice. Yes you are right I should put in more details.

I have worked out the issue. The problem was that the reports!YourReportName.recordsource was invoked in a function. If I move reports!YourReportName.recordsource to the on load even of the report, it is all fine.
 

Users who are viewing this thread

Top Bottom