Access 365 VBA DoCmd.OutputTo仅在客户笔记本报2501错误求助
Access DoCmd.OutputTo 导出PDF时仅在客户机器触发Error 2501/2487问题
本文是此前《DoCmd.OutputTo just stops after some rows when creating PDFs》问题的续篇,目前存在仅在客户笔记本上执行DoCmd.OutputTo代码时触发Error 2501的问题。
已完成的排查工作
- 搭建与客户环境一致的Win11x64Pro+Microsoft 365虚拟机,默认打印机设为Microsoft Print to PDF,程序运行无报错;
- 将客户笔记本默认打印机改为Microsoft Print to PDF,问题未解决,原默认打印机为通过WLAN连接的HP ColorLaserJet M255dw;
- 确认客户与虚拟机的Access版本均为Microsoft® Access® für Microsoft 365 MSO (Version 2301 Build 16.0.16026.20196) 32位;
- 目标文件夹已添加至Access信任位置。
测试现象
- 新建简单报表导出PDF和XLS均正常;
- 实际业务程序导出XLS正常,但导出PDF时触发Error 2501;
- 调试多种DoCmd.OutputTo参数组合,仍触发Error 2501或Error 2487。
核心VBA代码
Public Function fctPrintPDFs() as Long ... DoCmd.OpenReport ReportName:=strRptName _ , View:=acViewPreview _ , Filtername:="" _ , WhereCondition:="" _ , WindowMode:=acHidden DoCmd.OutputTo ObjectType:=acOutputReport _ , ObjectName:="" _ , OutputFormat:=acFormatPDF _ , OutputFile:=strRetCompletePathPDF _ , AutoStart:=False _ , OutputQuality:=acExportQualityPrint DoCmd.Close acReport, strRptName, acSaveNo ...
参数调试测试结果
'DoCmd.OutputTo acOutputReport, strRptName, acFormatPDF, strRetCompletePathPDF, , , , acExportQualityPrint 'DoCmd.OutputTo acOutputReport, "", acFormatPDF, strRetCompletePathPDF, , , , acExportQualityPrint '=> ERROR 2487 'DoCmd.OutputTo acOutputReport, , acFormatPDF, strRetCompletePathPDF, True '=> Error 2487 'DoCmd.OutputTo acOutputReport, , acFormatPDF, strRetCompletePathPDF, , , , acExportQualityPrint '=> Error 2487 'DoCmd.OutputTo acOutputReport, , acFormatPDF, strRetCompletePathPDF '=> Error 2501 'DoCmd.OutputTo acOutputReport, , acFormatPDF, "J:\test\SpB2023\Test1.pdf" '=> Error 2487 'DoCmd.OutputTo acOutputReport, "", acFormatPDF, "J:\test\SpB2023\Test1.pdf" '=> Error 2501 'DoCmd.OutputTo acOutputReport, "", acFormatPDF, "J:\test\SpB2023\Test1.pdf", True '=> Error 2487 DoCmd.OutputTo acOutputReport, "", acFormatPDF, "J:\test\SpB2023\Test1.pdf", False '=> Error 2501
错误说明
- Error 2501:
The OutputTo action was canceled.(输出操作已取消) - Error 2487:
The 'ObjectType' argument of this action or method is either not specified or invalid.(此操作或方法的'ObjectType'参数未指定或无效)
现寻求解决该问题的技术方案。
内容的提问来源于stack exchange,提问作者candide
相关产品推荐
相关产品推荐

