3

I have an Access VBA macro that generates a report, saves it in .pdf and then sends it by e-mail using CDO. Everything works fine if I run it manually or if I set it to be run on Task Scheduler with the security option "Run only when user is logged on". However, if I set the option to "Run whether user is logged on or not" (even with the option "Run with highest privileges") the program crashes on the second line of:

strFileFullPath = CurrentProject.Path & "\Test Report.pdf" DoCmd.OutputTo acOutputReport, strReportName, acFormatPDF, strFileFullPath

with the error

Microsoft Access can't save the output data to the file you've selected.

I am pretty sure that this happens because the macro runs with other user in the background. I have been searching for a solution but all I have found is that it is not possible and that I should change for other printing methods, such as PDF Creator (which brings a lot of other issues).

I am using Access 2016 in Windows Server 2012 R2 Standard.

Francisco Cruz
  • 195
  • 2
  • 12
  • Can you specify the value for strFileFullPath ? Is it in a folder specific to a user ? – Joel Gauvreau May 03 '16 at 17:48
  • Is in the same folder as the Access file. I have tested a macro that writes a dummy text file to that folder, so I guess it is not a user permission problem. – Francisco Cruz May 03 '16 at 18:16

1 Answers1

10

It sounds crazy, but after a few days with no results, I managed to solve my problem just by creating these two empty folders:

  • C:\Windows\System32\config\systemprofile\Desktop
  • C:\Windows\SysWOW64\config\systemprofile\Desktop

All the credits to Faye's comment on the bottom of this page: https://blogs.technet.microsoft.com/askperf/2015/02/18/help-my-scheduled-task-does-not-run/

Although the comment regards Excel, it solved my issue on Access. It seems that is related with Office having trouble with running some processes (in my case, a pdf generation) in non-interactive mode (which is the mode that Task Scheduler runs when "Run whether user is logged on or not" is checked).

Francisco Cruz
  • 195
  • 2
  • 12
  • Great tip. Didn't even know it was possible. Thanks! – Gustav May 08 '16 at 20:00
  • Again credit to Faye (and you). Worked for me, trying to use powershell & $db.DoCmd.OutputTo( 3,"$report",'PDF Format (*.pdf)',"$report_local" ), same issues with Task Scheduler. In my case running 32-bit MSAccess it was the SysWOW64 folder creation wot solved it. – EndUzr Nov 22 '16 at 12:03
  • Awesome thanks! Also struggled a bit. In my cause it was also a space in the path – Shaun Vermaak Dec 07 '16 at 09:24