PDF Conversion Issues

How to Export an Access Report to PDF with a Dynamic File Name

John WilsonJohn Wilson Nov 3, 2026 869 views

Question details

The user needs to export a filtered Microsoft Access report as a PDF while automatically generating a default file name based on dynamic database fields like album title and artist.

How to Export an Access Report to PDF with a Dynamic File Name
Product
Microsoft Access
Device & OS
not provided
Scenario
Generating custom PDF reports directly from an Access database and prompting the user with a pre-filled Save As dialog to choose the destination.
Observed behavior
The user requires a VBA method to concatenate dynamic fields into a default file name, sanitize it, and pass it to the PDF export function while handling the save dialog.
Before you start

Ensure you have basic familiarity with Microsoft Access VBA (Visual Basic for Applications). Before running the code, verify that the database fields you intend to use for the file name do not contain invalid characters like slashes or asterisks.

Solution 1Recommended

Use VBA and Application.FileDialog to Export Report

Utilize a custom VBA script to open a Save As dialog, pre-fill the dynamic file name, and export the report as a PDF.

By combining the Application.FileDialog object with the DoCmd.OutputTo method, you can dynamically construct a file name from your form fields and prompt the user to select a save location.

1
Open the VBA Editor

Press ALT + F11 to open the VBA editor in Microsoft Access.

2
Create a New Module

Right-click in the Project Explorer, select Insert, and choose Module to write your export script.

3
Sanitize File Names

Write a helper function using the Replace() method to remove invalid characters (e.g., \, /, :, *, ?, ", <, >, |) from the album title and artist strings.

4
Configure Application.FileDialog

Create a subroutine that initializes Application.FileDialog(msoFileDialogSaveAs), sets the InitialFileName property by combining your sanitized dynamic fields with a .pdf extension, and applies a PDF file filter.

5
Export via DoCmd.OutputTo

Inside your subroutine, capture the user's selected file path and use DoCmd.OutputTo acOutputReport, "YourReportName", acFormatPDF, SelectedPath to execute the PDF export.

Use VBA and Application.FileDialog to Export Report
Microsoft Office Reference: If you encounter errors with Application.FileDialog, ensure that the 'Microsoft Office Object Library' is enabled under Tools > References in the VBA editor.
Free Microsoft Office alternative

Looking for a Free Office Suite?

While Microsoft Access is a specialized database tool, WPS Office is an excellent, free alternative for your everyday document, spreadsheet, and presentation needs. It seamlessly converts documents to PDF without the need for complex VBA scripting.

Fully compatible with Microsoft Word, Excel, and PowerPoint formats.Built-in, easy-to-use PDF conversion tools requiring no code.Lightweight design that uses minimal system resources.Familiar user interface for a seamless migration.
microsoft office alternative - wps office

Frequently Asked Questions

How do I remove invalid characters from dynamic file names in VBA?

You can use the Replace() function in VBA to substitute forbidden characters like slashes, asterisks, and question marks with an underscore or an empty string before assigning the file name to the dialog.

Can I export an Access report to Excel instead of PDF using similar code?

Yes, you can use the same FileDialog approach, but you will need to change the acFormatPDF parameter in DoCmd.OutputTo to an Excel format like acFormatXLSX.

Why is my DoCmd.OutputTo exporting the entire table instead of a filtered report?

DoCmd.OutputTo exports the object exactly as it is opened. To export a filtered version, you should open the report invisibly with a WHERE clause using DoCmd.OpenReport first, and then run DoCmd.OutputTo.