Hey all,
Hoping someone has insight into what is going on with the issue I'm facing.
Problem
I have a Python script that exports a report from an Access Database to a PDF file. The script itself works fine when run manually, however when that same exact script is added to Task Scheduler (as a Python or batch file), the script fails due to the following error:
(-2147352567, 'Exception occurred.', (0, None, "Contact Management Database can't save the output data to the file you've selected.", None, -1, -2146825986), None)
I don't understand why I can run the script manually and have it work as expected, but when running via Task Scheduler, it gives me that error.
Script
import win32com.clientfrom pathlib import Path
from UtilityBelt import write
access_db_path = Path(r'<Access Database Path>')
report_name = r'<Name of Report in Access>'
report_output = Path(r'<Export folder>\test.pdf')
if report_output.exists():
# Deletes existing report if applicable
report_output.unlink()
try:
a = win32com.client.gencache.EnsureDispatch("Access.Ap plication")
# Open the database
db = a.OpenCurrentDatabase(access_db_path)
# Exports the selected report to a PDF
a.DoCmd.OutputTo(3, report_name, r'PDF Format (*.pdf)', str(report_output))
a.Application.Quit()
except Exception as e:
write(logfile, str(e))
Relevant Task Scheduler Settings
General
- Run whether user is logged in or not
- Run with highest privileges
Actions
- Program/script
- <path to folder>\access_testing.bat
- Start in (optional)
- <path to folder>
Batch File
@echo off"<path to python folder>\python.exe" "<path to folder>\access_testing.py"
pause
I've tried creating a brand new test access database, logging out then back in, restarting the computer, running in Task Scheduler via Python and Batch, playing with the action parameters, exporting to a local drive as opposed to a network drive, exporting a different file type, running with a different user, ... No luck with anything I've tried.
Any help would be very much appreciated.
Thanks all