Fix PDF Attachment Fails in Microsoft Access Script
Question details
The user is experiencing an issue where a PDF file fails to attach to an email generated through a Microsoft Access script.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Running an automated VBA script in Microsoft Access designed to generate a PDF and attach it to an outgoing email.
- Observed behavior
- The script fails to attach the PDF to the email, typically because a recent security update restricted the script's permission to write files to the root directory.
Verify if your system recently installed a Windows or Office security update, and note any specific error messages (like 'Permission Denied') that appear when the macro runs.
Update Script Folder Path and Permissions
Modify your Access VBA script to save the generated PDF in a user-accessible directory instead of a restricted system root directory.
Recent security updates often prevent applications from writing directly to the root of the C:\ drive to protect system integrity. Modifying your script to use a permitted folder will bypass this restriction.
Open your Microsoft Access database and press ALT + F11 to launch the Visual Basic for Applications (VBA) Editor.
In the Project Explorer pane, find and open the module that contains your email and PDF generation script.
Find the line of code that sets the save path for the PDF (e.g., 'C:\Report.pdf'). Change this path to a user directory that doesn't require administrator rights, such as 'C:\Users\Public\Documents\Report.pdf'.
Save your VBA code, close the editor, and run the Access macro again to verify that the PDF generates and attaches to the email successfully.

Whitelist the Folder in Security Software
Configure Windows Defender or your third-party antivirus to allow scripts to run and write files in your designated Access folder.
Looking for a Hassle-Free Office Suite? Try WPS Office
If complex script errors, restrictive security updates, and macro issues in Microsoft Office are disrupting your workflow, consider switching to WPS Office. It provides a lightweight, highly compatible, and user-friendly alternative for managing all your documents without the headache of constant configuration.
- 1. Download the Installer: Visit the official WPS Office website and download the free installation package.
- 2. Install WPS Office: Run the setup file and follow the quick on-screen instructions to install the suite on your device.
- 3. Enjoy Hassle-Free PDF Management: Open WPS Office to seamlessly edit, convert, and share PDFs natively without relying on complicated external scripts.

Frequently Asked Questions
Why does my MS Access script suddenly say 'permission denied' when attaching a PDF?
Recent Windows or Office security updates frequently restrict applications from writing files directly to the root C:\ drive to prevent unauthorized system changes. Changing the output directory in your VBA code to a standard user folder usually resolves this.
How can I find out exactly why my Access macro is failing?
You can add error handling to your VBA script. Insert 'On Error GoTo ErrorHandler' at the beginning of your procedure, and at the end, use a message box like 'MsgBox Err.Description' to display the exact reason the PDF attachment fails.
Do I need administrator privileges to run scripts that generate PDFs?
Not necessarily. If your script outputs the PDF to a standard user directory (such as Documents, Desktop, or the Temp folder), standard user permissions are sufficient to create and attach the file.




