Link to home
Start Free TrialLog in
Avatar of AndyAinscow
AndyAinscowFlag for Switzerland

asked on

Strange problem with exporting access report in pdf format

Access 2013 (accdb format) database.

I have to following code to open an access report in preview, export to pdf and then close the report (the szWhere is a filter string):
    'Preview the report
    DoCmd.OpenReport szDocName, acViewPreview, , szWhere
    
    '*****************************************************************************************
    DoCmd.OutputTo acOutputReport, , acFormatPDF, szFileName, False
    '*****************************************************************************************
    
    DoCmd.Close acReport, szDocName

Open in new window


In development it works perfectly.  In the production environment this code has stopped working.  It has been working for ca 18 months without problem.  It fails on the OutputTo line.
Interestingly on the production PC if a report is opened in preview mode manually, then the export to pdf/xps option chosen the report is exported without problem.

I'm stuck - the functionality works when run manually but not automatically.  Any ideas as to what the problem could be and how to get it working again.
Avatar of Anders Ebro (Microsoft MVP)
Anders Ebro (Microsoft MVP)
Flag of Denmark image

If I had to guess it could be a timing thing. I think the docmd works on the active object, if you haven't specified an object by name. Try being explicit about which opject to export:
 DoCmd.OpenReport szDocName, acViewPreview, , szWhere
    

    DoCmd.OutputTo acOutputReport,szDocName , acFormatPDF, szFileName, False

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I had this recurring problem before and prevented it from happening by adding codes to check if the folder exists and if it don't exists, create the folder before running the codes.
Avatar of AndyAinscow

ASKER

Missing folder.