Results 1 to 4 of 4
  1. #1
    louise is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    112

    Need Message and don't open report if report has no records

    Hello,


    I have a button on a form, designed to open a report. I have created a message to come up if the report has no records. The message does come up, but, when I close the message, I get an error related to the button's OnClick event: Macro error 2501, and the DoCmd OpenReport line is highlighted.

    This is the code I have for Report's NoData event:
    Private Sub Report_NoData(Cancel As Integer)
    MsgBox "The requested waiting list has no names on it", vbOKOnly, "Error"
    Cancel = True
    End Sub

    This is the code I have for the button on the form, designed to save and then open the report: (clicking this button brings up the "no records" message, but then the error when you close out the message.)
    Private Sub butWaitingList_Click()
    DoCmd.RunCommand acCmdSaveRecord
    'Print Preview Waiting List
    'using [RPTLimited-WaitingList]
    DoCmd.OpenReport "RPTLimited-WaitingList", acViewPreview, , "RandCourseDetailsID = " & Me!RandCourseDetailsID
    End Sub

    The button seems to trigger the report's "No data message" but then still tries to open the report.
    Any help would be great!

    Thanks!

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You need error handling in the button code:

    http://www.baldyweb.com/ErrorTrap.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    louise is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Apr 2015
    Posts
    112
    thanks very much! I can see from this and related webpages that I then found, that I have other work to do to have error handling in hand.
    I was able to solve my immediate issue.

    I appreciate your help!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 3
    Last Post: 07-22-2014, 11:37 AM
  2. Open a report only if query has some records
    By Ganymede in forum Reports
    Replies: 1
    Last Post: 06-12-2014, 04:00 PM
  3. Replies: 4
    Last Post: 06-03-2014, 10:30 AM
  4. Replies: 1
    Last Post: 08-01-2011, 04:17 PM
  5. Replies: 2
    Last Post: 05-26-2011, 12:15 PM

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