【问题标题】:MS Access export report from another databaseMS Access 从另一个数据库导出报告
【发布时间】:2015-10-10 02:36:51
【问题描述】:

我基本上是在尝试执行以下操作(导出为 PDF 报告):

DoCmd.OpenReport report_name, acViewPreview
DoCmd.OutputTo acOutputReport, report_name, acFormatPDF, dest, False
DoCmd.Close acReport, report_name

但是我试图让它引用一个完全独立的数据库中的报表对象。如何修改 report_name 以使其正常工作?我试过“[dbpath].[report_name]”无济于事。报告名称中包含空格,如果这很重要的话。

【问题讨论】:

    标签: ms-access pdf vba export


    【解决方案1】:

    创建一个新的 Access 应用程序会话,打开另一个数据库,并将该会话用作您的 Application.DoCmd 方法的主机应用程序。

    Dim objAccess As Access.Application
    Set objAccess = New Access.Application
    
    objAccess.Visible = True ' <- useful during development
    objAccess.OpenCurrentDatabase "C:\wherever\YourDatabase.accdb"
    With objAccess.DoCmd
        .OpenReport report_name, acViewPreview
        .OutputTo acOutputReport, report_name, acFormatPDF, dest, False
        .Close acReport, report_name
    End With
    objAccess.CloseCurrentDatabase
    objAccess.Quit
    Set objAccess = Nothing
    

    【讨论】:

    • 执行“new access.application”是否有任何原因可能导致引用错误?由于这个原因,我有时听说后期绑定比早期绑定更好。
    • Access.Application 不是问题。您在 Access 中运行 VBA 代码,默认情况下,您的项目具有 Access 对象库的引用,并且它是正确的版本。后期绑定在您无法确定参考的预期版本是否可用的其他情况下很有用;甚至该参考的任何版本是否可用。
    猜你喜欢
    • 1970-01-01
    • 2016-09-14
    • 1970-01-01
    • 2014-08-18
    • 2013-12-04
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多