Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291

    Run-time error '2501' The OpenReport action was canceled

    I have a way to open a report, but if there is no data current when I open the report it gives me a run time error and crashes.

    The code I am using to call
    Code:
    Private Sub cmbPrintManhole_Click()
        Dim str1 As String
        If Me.cmbArea = "ALL" Then
            DoCmd.OpenReport "PEC_StormDrainManholeReport", acViewPreview, , "[Manhole Number (12)] <> """""
        Else
            str1 = Me.cmbArea
            DoCmd.OpenReport "PEC_StormDrainManholeReport", acViewPreview, , "[Area] ='" & str1 & "'"
        End If
    End Sub
    Under the report that is being called I have the "On No Data" Property set to the following code:
    Code:
    Private Sub Report_NoData(Cancel As Integer)
        MsgBox "No records in current selection"
        Cancel = True
    End Sub
    When I click the button to Open the report in print view it brings up a message box like it is suppose to then after I click OK it brings up a Run-time error'2501': The OpenReport action was canceled.

    Any help would be appreciated, thank you.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It looks right. I would start by *importing* your db into a fresh, new db and see if the problem follows. http://www.btabdevelopment.com/ts/impnew

  3. #3
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    I imported it to a fresh file and the problem was still there. :-(

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Hmm...is your ac2003 fully patched including the HotFixes? If you comment out the MsgBox but leave the Cancel = True does it still give you the RunTime error?

  5. #5
    cowboy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2010
    Posts
    291
    I forgot to update my version, I am using Access 2010. I commented out the msgbox and got the same error.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You have error handling code in your cmbPrintManhole button don't you? Canceling the report causes the 2501 error.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Did I lose you there?

  8. #8
    cowboy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2010
    Posts
    291
    Sorry I was busy with something else for a second, but I dont have code under the cmbPrintManhole button for error handling, is there a place on the properties or something that error handling can be held? I am not very familiar with error handling.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Do you have any code in the OnError event of your form?

  10. #10
    cowboy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2010
    Posts
    291
    I have nothing under the On Error property on my form which has the button or the report that is being opened.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Let's go the other way. The default for ac2010 is "Break on Unhandled Errors". Let's add error handling to the procedure. Replace what you have with:
    Code:
    Private Sub cmbPrintManhole_Click()
       On Error GoTo Err_cmbPrintManhole_Click
       Dim stDocName As String
       stDocName = "PEC_StormDrainManholeReport"
       If Me.cmbArea = "ALL" Then
          DoCmd.OpenReport stDocName, acViewPreview, , "[Manhole Number (12)] <> ''"
       Else
          DoCmd.OpenReport stDocName, acViewPreview, , "[Area] ='" & Me.cmbArea & "'"
       End If
    Exit_cmbPrintManhole_Click:
       Exit Sub
    Err_cmbPrintManhole_Click:
       If Err <> 2501 Then
          MsgBox "Error Number: " & Err.Number & vbCrLf & _
                 "Description:  " & Err.Description
       End If
       Resume Exit_cmbPrintManhole_Click
    End Sub

  12. #12
    cowboy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2010
    Posts
    291
    Well that worked, thank you very much. I will go back and look at what is actually going on to learn for next time.

  13. #13
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It took that second cup of coffee this morning to get my brain started.

  14. #14
    cowboy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2010
    Posts
    291
    So after looking back at what the code does, it looks like we just let the error occur but when error 2501 occurs just we tell the program what to do instead of crash. Does that sound right?

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Exactly right! By canceling the ReportOpen, we in effect have created the 2501 error which is passed back to the OpenReport procedure and needs to be handled by that procedure. In this case we will display all *but * the 2501 error.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 12-10-2018, 05:24 PM
  2. Replies: 2
    Last Post: 12-23-2010, 09:11 AM
  3. Replies: 2
    Last Post: 12-02-2010, 02:35 AM
  4. Action Failed -Error Number: 2950
    By Cindy in forum Access
    Replies: 5
    Last Post: 07-07-2010, 11:51 AM
  5. Run Time Error 424
    By ddog171 in forum Programming
    Replies: 3
    Last Post: 02-04-2006, 07:13 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