DoCmd.Output action

Anonymous
2023-09-06T14:59:18+00:00

I have some code that generates a report unique to each grower that outputs the report as a PDF document to a unique folder based on the grower's name. It has been working fine for years and is till working fine....somewhat. For some reason it works great for every grower but one. It works perfect for the grower before and after the one the problem occurs with. When it goes to do the output for the one grower I get the following error message:

Error - 2501 : The OutputTo action was canceled.

The code is listed below and the line throwing the error message is in bold.

As you can see I have added some debug.print statements to try in help in figuring out the problem.

  • stRptName is the name of the access report (rptDefectsReport)
  • stPathpdfName is the PDF file name including the full path to where the file is to be saved

Can anyone shed any light on what might be going wrong with this one grower?

Code:

Sub SaveRptPDF(stRptName As String, stPathPdfName As String)

On Error GoTo ErrorHandler

'Form Name  -  Procedure Name 

strProdName = "modEmailReports -> SaveRptPDF" 

Debug.Print "stRptName: " & stRptName

Debug.Print "stPathpdfName: " & stPathPdfName & vbCrLf & vbCrLf

'DoCmd.OpenReport "rptIntakeGrowerStatements", acViewPreview

'save report as PDF 

**DoCmd.OutputTo acOutputReport, stRptName, acFormatPDF, stPathPdfName, False** 

If stPathPdfName = "K:\Grower Portal\EISSES\_FARMS\_LTD\Pool\Defects\2021\_Defect\_Report\_Grower.Pdf" Then 

    stPathPdfName = "K:\Grower Portal\EISSES\_FARMS\_LTD\Pool\Defects\2021\_Defect\_Report\_Grower.xls" 

    DoCmd.OutputTo acOutputReport, stRptName, acFormatXLS, stPathPdfName, False 

End If 

ExitProdcedure:

Exit Sub 

ErrorHandler:

MsgBox "Error: " & strProdName & " - " & Err.Number & " : " & Err.Description & "  Please record this message and contact IT.", vbOKOnly + vbInformation 

Resume ExitProdcedure

On Error GoTo ErrorHandler

End Sub

Microsoft 365 and Office | Access | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

4 answers

Sort by: Most helpful
  1. Anonymous
    2023-09-06T17:48:25+00:00

    Sure. There was not a problem with the code but a problem with the data being used by one of the queries be accessed by the code.

    Was this answer helpful?

    0 comments No comments
  2. Tom van Stiphout 40,211 Reputation points MVP Volunteer Moderator
    2023-09-06T17:41:12+00:00

    For the benefit of the community, can you please share the solution?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-09-06T17:26:39+00:00

    Thanks for the suggestion. I appreciate the assistance.

    I found the problem and it has been corrected.

    Was this answer helpful?

    0 comments No comments
  4. Duane Hookom 26,840 Reputation points Volunteer Moderator
    2023-09-06T15:37:15+00:00

    What are the debug.prints?

    Are there any special characters in the path?

    Was this answer helpful?

    0 comments No comments