Get 15 minutes of free Live Help!

“Folder In Use” Error After Using DoCmd.OutputTo for PDF Export


I got a “Folder In Use” error after using a loop that included the macro action to export a Microsoft Access report to PDF files.  The error occurred when I tried to rename the folder that the PDF files were exported to.

OutputTo Folder In Use Error

Using the DoCmd.OutputTo created a handle on the folder itself that was not released at the end of the function, preventing me from altering the folder.  I could delete the files in the folder, but not rename the folder.

To fix the problem, I used the method after the call to DoCmd.OutputTo in the loop to ensure that all outstanding MS Access or Windows-related events were processed before starting through the loop again.


Dim intCounter As Integer
Dim strReportName As String
Dim strPath As String

strPath = "C:\ExportFolder\"

For intCounter = 1 To 10
    strReportName = "Report" & intCounter & ".PDF"
    DoCmd.OutputTo acOutputReport, "Report", acFormatPDF, _
        strPath & strReportName, False
Next intCounter

Leave a Reply

Your email address will not be published. Required fields are marked *

Live Chat Software