How to Fix Microsoft Access PDF Export Errors for a Single Record
Question details
The user needs to resolve an issue where an Access form successfully exports to PDF for most records, but consistently fails to generate the output for one specific record.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Exporting database form records to PDF files using a VBA macro (DoCmd.OutputTo), where the file name is generated dynamically using record data and dates.
- Observed behavior
- The PDF generation crashes or fails for only one specific record, likely due to invalid characters, excessive length, or null values present in the generated filename string.
Ensure you create a backup copy of your Access database before modifying the VBA code or altering the data of your records.
Use a String Variable and Debug.Print to Identify Invalid Data
By assigning the generated filename to a variable and printing it in the Immediate Window, you can spot illegal characters or missing data that are causing the PDF export to fail.
When generating filenames dynamically in Access using form data, certain records might contain characters that Windows does not allow in file paths. Debugging the exact string helps pinpoint the exact data entry issue.
Press Alt + F11 while in Microsoft Access to open the Visual Basic for Applications (VBA) Editor, and locate the code block responsible for exporting the form.
Change any plus signs (+) used for string concatenation in your file path generation to ampersands (&) to handle null values more gracefully.
Create a new string variable (e.g., Dim strFileName As String) and assign your concatenated file path to this variable instead of putting it directly into the OutputTo command.
Insert the command 'Debug.Print strFileName' immediately before your DoCmd.OutputTo line.
Run the code until it fails on the problematic record. Press Ctrl + G to open the Immediate Window and review the printed file path for illegal characters or missing names.

Check the Specific Record for Corrupted or Missing Data
Examine the actual data entered in the Access form for the problematic record to ensure all required fields used for the filename are populated correctly.
Looking for a Free and Lightweight Office Suite?
While WPS Office does not feature a direct database equivalent to Microsoft Access, it serves as a highly compatible and free alternative for Word, Excel, and PowerPoint files with built-in PDF tools.
- 1. Download WPS Office: Visit the official WPS Office website and click the free download button to get the installer.
- 2. Install the Software: Run the downloaded executable file and follow the on-screen instructions to complete the installation process.
- 3. Manage Office Files and PDFs: Launch WPS Office to open, edit, and save your existing Word, Excel, PowerPoint documents, and PDF files seamlessly.

Frequently Asked Questions
Why does my Access PDF export fail for only one record?
This usually occurs because the specific data inside that record contains forbidden characters, excessive lengths, or null values that create an invalid Windows file path when the VBA script tries to generate the PDF filename.
Why should I use ampersands (&) instead of plus signs (+) for string concatenation in Access VBA?
Ampersands are explicitly designed for string concatenation in VBA and handle Null values gracefully. Using a plus sign can sometimes cause VBA to attempt mathematical addition or return a Null result if one part of the string is missing.
How do I view the output of a Debug.Print command in Access?
You can view the output by opening the Immediate Window in the VBA Editor. To do this, open the VBA Editor (Alt + F11) and press Ctrl + G on your keyboard.
Can I automatically strip invalid characters from filenames in Access VBA?
Yes, you can write a custom VBA function using the Replace() method to automatically search for and remove invalid characters like slashes, colons, or asterisks from the form data before it is used to generate the filename.




