Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    New Jersey, USA
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    NoData event (97 sr2)

    Is there a trick to getting the NoData event to work? I have it set to print out an alternate report if there is no data. The problem is it prints the report that contains no data first and then the alternate report. I am sure I am just missing something simple, but I don't know what it is.

    Thanks
    Cathy

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: NoData event (97 sr2)

    The NoData event should return a value to the calling form or routine and cancel the printing of the report with no data. Then the code that opened the first report should open the alternate report instead. If you post the code you're using, someone can help you straighten it out to get the correct results.
    Charlotte

  3. #3
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    New Jersey, USA
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: NoData event (97 sr2)

    Thanks for your quick response.

    I think I need someone to show me the code. I am not sure where to start

    Thanks

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: NoData event (97 sr2)

    How are you trying to make it work now? There's no point in posting code that goes off in a different direction. We need a starting point to help you within the context of what you're actually doing. If you are not familiar with VBA code, you need to make that clear as well, or you may get an answer that just confuses you.
    Charlotte

  5. #5
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    New Jersey, USA
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: NoData event (97 sr2)

    To begin with this gives me a problem Runtime error 2501 Open Report action was canceled. Yet in the book I have it appears to be all I have to do. Obviously that is not correct!

    Private Sub Report_NoData(cancel As Integer)
    cancel = True
    End Sub


    This is on the main menu form and I thought I would print the alternated report here, but that does not work either.
    Private Sub CMDPRINT_Click()
    Dim stDocName As String
    stDocName = "Rpt: Joint Acct Activity"
    DoCmd.OpenReport stDocName, acPreview
    End Sub

    I do know VB but for some reason this event does not make sense to me. I am sure I am completely off the track so any help in making this work would be greatly appreciated.

    Thanks
    Cathy
    : ) : )

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: NoData event (97 sr2)

    What's happening is this: When the NoData event of the report fires, it cancels the report. The fact that the report has been cancelled conflicts with the OpenReport command, and you get an error 2501. The common way of handling that "error" is to trap for it and then ignore it. In your case, you want to trap for it and then print the alternate report. Access events can be a bit more complex than VB events, so sometimes it's hard to switch back and forth.
    Charlotte

  7. #7
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    New Jersey, USA
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: NoData event (97 sr2)

    Charlotte,
    I am still having problems with this. I print the original report in an on click event on a form. If there is no data I capture the error and print the alternate report in the error handling section of the nodata event. This works fine, but then the original report tries to run and the error 2051 comes up again. I must be missing something here. I thought I could pass a parameter back to the on click event but apparently it is not allowed. Is there an easier way to do this? It seems like what I want to do should be very simple.

    Cathy

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: NoData event (97 sr2)

    I see. No you should trap the 2501 error in the form and then print the alternate report from the form, not from the NoData event of the report. The only thing you want to do in the NoData event is cancel the report. That will trigger the 2501 error in the calling form and you can then print the alternate report from there. You have the right idea, you're just trying to do it in the wrong place.

    You can monitor the report's events from the form with VBA code, but it is a bit more complicated than working with a class in VB, so I'd suggest you do it the easy way.
    Charlotte

  9. #9
    2 Star Lounger
    Join Date
    Aug 2002
    Location
    New Jersey, USA
    Posts
    180
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: NoData event (97 sr2)

    Charlotte,
    Thanks for your help. It works!

    Cathy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •