none
Create PDF from Access Report using a Service RRS feed

  • Question

  • We have an Access database (MDB) that we have coded to open a report in preview mode, then use DoCmd.OutputTo and save it as a PDF.  This works fine if I run it by opening the MDB while holding Shift and then manually triggering my Startup form.  It also works fine if I open the MDB and let it automatically load the Startup form as well.

    So we created a service that will detect when this needs to run, and open the MDB if necessary, displaying the GUI on the currently logged in users desktop. If we set the service to start as the Local System user, the PDF will not create. It returns an error 2501 - OutputTo action was cancelled. If we change our service to start as a specific user, everything works, except our GUI doesn't appear for this user.  We need the GUI in certain cases, so this isn't an acceptable option unfortunately.

    What can I do to allow the PDF to be created when running this service as Local System?

    Tuesday, October 31, 2017 3:36 PM

Answers

  • Just an update - found a different way to create the PDF. Instead of using the built in OutputTo method, I used Stephen Lebans' dll's and modules (found here: http://www.lebans.com/reporttopdf.htm) and it now creates the PDF.

    Not a direct answer to the question I posed - but it is an alternative solution to my problem.

    • Marked as answer by Scott Stairs Tuesday, October 31, 2017 9:37 PM
    Tuesday, October 31, 2017 9:07 PM

All replies

  • Why do you need a service?  Do you mean a Windows Service that you install as part of the installation of your database?

    What version of Access are you running?  Since Access 2007+ all have the ability to create PDF natively and prior to 2007 (2003-) there were numerous way to do so, most notably Stephen Lebans' Report to PDF.

    I think we're going to need more information to help you any further.


    Daniel Pineault, 2010-2017 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Tuesday, October 31, 2017 4:06 PM
  • We created an EXE that runs as a Windows Service. We install it with our software. We install it both on servers and on workstations depending on the site configuration, and want it to be a background service that doesn't *require* user interaction but if a user is logged on, it will allow it. We also don't want to worry about changing the service if the user changes their password, so we need it to run under the Local System or similar built-in account.  Its job is to monitor a database for requests to email specific invoices, and then create a PDF and email it.

    Basic idea of the code we're using to create the PDF is shown below:

    140           DoCmd.OpenReport "MasterReport", acViewPreview
    ...
    210           DoCmd.OutputTo acReport, "MasterReport", "PDF Format (*.pdf)", strFilePath
    ...
    310           DoCmd.Close acReport, "MasterReport", acSaveNo
    

    Access 2007 is the primary version we are using, and it works perfect when we run it manually or run the service as a user account. However - running the service as the Local System account, we get error 2501 at line 210. The report opens fine at line 140, but its the creation of the PDF *when starting the service using the Local System account* that is giving us problems.

    Tuesday, October 31, 2017 4:41 PM
  • I can't help you with the Service aspect of it.

    I just don't get why you need such a service.  Why not handle it all in the db from which the request originates and the ability to generate the PDF exists, but that an entirely other debate and won't solve your current issue.  Hopefully someone else that knows a thing or two about creating Windows Services will chime in.  Good luck.


    Daniel Pineault, 2010-2017 Microsoft MVP
    Professional Support: http://www.cardaconsultants.com
    MS Access Tips and Code Samples: http://www.devhut.net

    Tuesday, October 31, 2017 5:24 PM
  • Sorry for any confusion.

    We *are* handling the PDF creation from within the MDB. The service's job is to start the database on demand. After the db has done its thing, it shuts down again. The service stay running in the background monitoring things.

    When I run the db as the current user through full version of Access 2007, run my Startup form manually, everything works and the PDF gets created.

    When I run the db as the current user through the runtime version of Access 2007, it automatically opens Startup form, everything works and the PDF gets created.

    When I enable the service as a specific user and password, it starts the db and works and the PDF gets created, but we can't use this because the password may change and it also is hiding the GUI for some reason (not worried about that right now).

    When I enable the service as the Local System user with Interactive Mode, it starts the db, loads the GUI like normal, opens the report in preview mode, but when it tries to call DoCmd.OutputTo, it returns error 2501 - OutputTo action was cancelled.

    Tuesday, October 31, 2017 5:36 PM
  • All I can suggest is making sure your service has proper permissions to all the file system elements in play here, i.e. the mdb file (or files, if you have a split database), the folder where the pdf file is being created, and the folder(s) where your mdb file(s) live.

    -Bruce

    Tuesday, October 31, 2017 6:43 PM
  • Just an update - found a different way to create the PDF. Instead of using the built in OutputTo method, I used Stephen Lebans' dll's and modules (found here: http://www.lebans.com/reporttopdf.htm) and it now creates the PDF.

    Not a direct answer to the question I posed - but it is an alternative solution to my problem.

    • Marked as answer by Scott Stairs Tuesday, October 31, 2017 9:37 PM
    Tuesday, October 31, 2017 9:07 PM