Results 1 to 7 of 7
  1. #1
    GinaFlan is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Location
    Texas
    Posts
    68

    Help The OutputTo action was canceled Run-time error '2501'

    Click image for larger version. 

Name:	Outputtoerror.PNG 
Views:	16 
Size:	27.9 KB 
ID:	18439
    I hope you can see the picture I attached.

    [Private Sub CmdReport_Click()
    Dim MyPath As String
    Dim MyFilename As String
    MyPath = "C:\Users\"
    MyFilename = Format(Me.ComboSummary) & ".pdf"

    Select Case Me.ComboSummary


    Case "Child Nutrition"
    DoCmd.OpenReport "Child Nutrition Report", acViewPreview
    DoCmd.OutputTo acOutputReport, "Child Nutrition Report", acFormatPDF, MyPath & MyFilename, True
    DoCmd.Close acReport, "Child Nutrition Report"
    End Select]
    Last edited by GinaFlan; 10-21-2014 at 07:32 AM. Reason: add another picture

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Are you sure , MyPath & MyFilename
    is a legal path?

    and that you can write to it?

    (try it manually)

  3. #3
    GinaFlan is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Location
    Texas
    Posts
    68
    I will try it manually & see if it works Thank you

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    What is Format supposed t be doing in this:

    MyFilename = Format(Me.ComboSummary) & ".pdf"

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    hansendl is offline Advanced Hobbyist
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    38
    In your code, you are closing the report immediately after the DoCmd.OutputTo line. Perhaps Access is trying to close the report before the OutputTo command has a chance to finish. Try commenting out the DoCmd.Close line and see if you still get the error. If not, you may need to create a DoEvents loop to give the OutputTo command time to finish before closing the report.

  6. #6
    hansendl is offline Advanced Hobbyist
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    38
    After running a quick test, you don't need to open the report before using the OutputTo command. Try deleting (or commenting out) the DoCmd.OpenReport and DoCmd.Close lines.

  7. #7
    hansendl is offline Advanced Hobbyist
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    38
    You will also get that error if the target file already exists and is open (or otherwise can't be overwritten). In that case, you will want to trap the error and either inform the user or change the filename.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 09-09-2014, 02:11 PM
  2. runtime error 2501 openform action was canceled
    By rumenrs in forum Programming
    Replies: 2
    Last Post: 04-11-2013, 04:29 AM
  3. Replies: 6
    Last Post: 11-28-2012, 03:43 PM
  4. Replies: 15
    Last Post: 07-26-2012, 02:06 PM
  5. Replies: 7
    Last Post: 07-18-2012, 07:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums