In VBA how do you return the name of an underlying query for a report object?

江枫思渺然 提交于 2019-12-11 07:49:20

问题


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


来源:https://stackoverflow.com/questions/651558/in-vba-how-do-you-return-the-name-of-an-underlying-query-for-a-report-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!