Page 1 of 3 123 LastLast
Results 1 to 15 of 38
  1. #1
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85

    2501 error

    I have a report that prints via a coded button. In the no data event for the report I placed the following code to prevent the report from printing if there is no data:

    MsgBox "There are no records meeting the criteria. If you believe this message is in error, please try again ", vbOKOnly, ""
    Cancel = True

    When I run the report I keep getting a 2501 error (2501 The open report action was cancelled).

    Am I missing a line of code in the original statement?

    Thanks for the help.

    Ron C

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I haven't tried it but I think you don't need the "Cancel = True" since you are already in an event that will exit the report.

  3. #3
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    No, that didn't work. Removing the "Cancel = True" statement caused the empty report to be printed. Thanks for the suggestion, it was worth a shot.

    Ron C

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I'm doing more research right now. I'll get back to you with any results. Thanks for trying it.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It looks like you are using it exactly right. Are you using code or a Macro?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    My ac2013 does not act like your system. Are you still using ac2010? Do you have any code in the Open event?

  7. #7
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    I'm using code attached to a button. I can kind of work around by putting code in the onerror procedure stating: "DoCmd.SetWarnings False" so the error message doesn't show up, but that seems like the wrong way to handle it.

    Thanks again.

    Ron C

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Where is the button located? On the report of on a form?

  9. #9
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    This happens when a procedure initiates a cancelable event and the event is cancelled. The calling procedure notifies you that the event it was calling was not completed. Seems reasonable when you think of what could happen if subsequent code depended on the event being completed.

    Create an error handling block in the calling procedure and trap for 2501. Exit sub/function or resume or resume next, etc. - whatever is appropriate.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    The button is on a form.

  11. #11
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by Micron View Post
    This happens when a procedure initiates a cancelable event and the event is cancelled. The calling procedure notifies you that the event it was calling was not completed. Seems reasonable when you think of what could happen if subsequent code depended on the event being completed.

    Create an error handling block in the calling procedure and trap for 2501. Exit sub/function or resume or resume next, etc. - whatever is appropriate.
    Micron,
    It does not do this on my ac2013 system Win10.

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The code you posted is in the OnNoData event of the Report, Right? Would you post all of that event code for us please, starting with: Private Sub Report_NoData(Cancel As Integer)

  13. #13
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    It is on the OnNoData event of the report. Here's the code:
    Private Sub Report_NoData(Cancel As Integer)
    MsgBox "There are no records meeting the criteria. If you believe this message is in error, please try again ", vbOKOnly, ""
    Cancel = True
    DoCmd.Close
    DoCmd.OpenForm "AppointmentSchedulerfrm", acNormal, "", "", , acNormal
    End Sub

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Ah Ha... Is the AppointmentSchedulerfrm the form with the button?

  15. #15
    Roncc is offline Advanced Beginner
    Windows 10 Access 2010 32bit
    Join Date
    Dec 2017
    Posts
    85
    Yes, it is the form that has the button that prints the report.

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

Similar Threads

  1. Run-time error 2501 for one user on one PC
    By TheBradish in forum Access
    Replies: 11
    Last Post: 06-13-2017, 04:02 AM
  2. Error 2501
    By Abacus1234 in forum Forms
    Replies: 3
    Last Post: 09-08-2015, 04:46 PM
  3. Do.cmd OutputTo Error 2501
    By Fuzz_cozens in forum Programming
    Replies: 7
    Last Post: 07-15-2014, 06:44 AM
  4. Error Handling 2501
    By RainyDay in forum Programming
    Replies: 7
    Last Post: 06-08-2013, 10:44 PM
  5. Error 2501 displays with Error handling
    By agent- in forum Programming
    Replies: 13
    Last Post: 08-05-2011, 02:20 PM

Tags for this Thread

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