Save Microsoft Access Reports to a Dynamic Folder with VBA
Question details
Export Access reports to a folder beside the current database, creating the folder if it does not exist.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- A VBA procedure needs to save financial reports in a Monthly Financial Reports folder without relying on a fixed directory path.
- Observed behavior
- Reports should be exported to a folder relative to the current database, with the folder created when needed.
Open the Access database and identify the report name and desired output filename. Make sure you have permission to create folders and files in the directory containing the database.
Create a Database-Relative Folder and Export the Report
Use the current database path to locate or create the export folder before saving a report as a PDF.
Application.CurrentProject.Path returns the folder containing the current database. Dir checks whether the export folder exists, and MkDir creates it when needed.
In Access, press Alt+F11, then choose Insert > Module to add a standard VBA module.
Paste this procedure into the module: Public Sub ExportFinancialReport() Dim exportFolder As String exportFolder = Application.CurrentProject.Path If Right(exportFolder, 1) <> "\" Then exportFolder = exportFolder & "\" End If exportFolder = exportFolder & "Monthly Financial Reports" If Dir(exportFolder, vbDirectory) = "" Then MkDir exportFolder End If DoCmd.OutputTo acOutputReport, "YourReportName", acFormatPDF, _ exportFolder & "\FinancialReport.pdf", False End Sub
Replace YourReportName with the name of your Access report and FinancialReport.pdf with the PDF filename you want. Repeat the DoCmd.OutputTo line with different report names and filenames to export additional reports.
Place the cursor inside ExportFinancialReport and press F5. Open the Monthly Financial Reports folder beside the database and check that the PDF was created.

Work with Financial Reports in WPS Office
WPS Office is a free, lightweight alternative for working with documents and spreadsheets in a familiar interface. Its Microsoft Office format compatibility helps you move existing files into WPS, although it does not run Access VBA or replace an Access database.

Frequently Asked Questions
Where will Access create the Monthly Financial Reports folder?
The folder is created inside the directory returned by Application.CurrentProject.Path, alongside the current database file.
What happens if the export folder already exists?
The Dir check finds the folder, so the procedure skips MkDir and exports the report to the existing folder.
How do I export more than one Access report?
Add another DoCmd.OutputTo line after the folder check for each report. Set the report name and use a distinct output filename for each PDF.
Why might the folder or PDF fail to be created?
Check that you can write to the database directory, that the report name in DoCmd.OutputTo is correct, and that a file with the intended folder name does not already exist.
Can WPS Office run this Access VBA procedure?
No. Run the procedure in Microsoft Access. WPS Office can instead help you work with compatible documents and spreadsheets exported from your workflow.




