In VBA how do you return the name of an underlying

2019-07-27 07:03发布

问题:

I would like to obtain the name of a query behind a specific report. I was hoping to do something like this...

 Dim QueryName As String
 QueryName = CurrentProject.AllReports(MyReportName).RecordSource.Name

However, I know this does not work, but I would like to find a means of doing this. Is there something I am obviously overlooking?

回答1:

You have to open the report to get access to those kinds of properties.

Open in design mode so you don't actually run the thing.

Dim QueryName As String

DoCmd.OpenReport MyReportName, acViewDesign

QueryName = Reports(MyReportName).RecordSource

DoCmd.Close acReport, MyReportName