Solved

Strange problem with exporting access report in pdf format

Posted on 2016-11-18
4
14 Views
Last Modified: 2016-11-23
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.
0
Comment
Question by:AndyAinscow
  • 2
4 Comments
 
LVL 5

Expert Comment

by:Anders Ebro (Microsoft MVP)
Comment Utility
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

0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 0 total points
Comment Utility
I have tried that but it didn't make any difference.  :-(

Found it.  For some reason the destination folder had been deleted !!  Creating it cures the problem.
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
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.
0
 
LVL 44

Author Closing Comment

by:AndyAinscow
Comment Utility
Missing folder.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now