Results 1 to 6 of 6

Thread: report question

  1. #1
    Join Date
    Nov 2003
    Posts
    300

    Talking Unanswered: report question

    I have a report that uses a form for the user to put in the parameters, usually the name of a manager and it will print out any activity for them in the date range that they select.

    If they select a manager with no data, however, it will print out a report that says #ERROR#.. where the data should be.

    Is there a way so that NO REPORT will be printed if the user selects a Manager that has no data to print?


  2. #2
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    In the report's No Data event,

    Cancel = True

    will stop the report from opening. Note that you will need to trap for error 2501 in the code that opens the report.
    Paul

  3. #3
    Join Date
    Nov 2003
    Posts
    300
    Thank you! That was simple.

    How do you trap for the error? You mean if that error comes up, then go back to the input form so they can enter in another manager?

    new to vba is why I am asking.

  4. #4
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    Here's a primer:

    Error trapping
    Paul

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    theres two ways of inhibiting that
    one is to do it at the form that requests the parameters, until you have data that will lead to a successful report you don't allow the report to be called. you find if you have data by running the same SQL as the rport and seeing if any records are returned.

    the other is to trap it in the reports nodata event as Pbaldy says. the no data event is probably best, and best of all the hard works been doen for you by Microsoft.

    you could put a msg box telling the user they are a twonk for selecting a parameter which generates no data then close the report

    to set the code view the report in design mode
    select view code
    you should see the code window appear, with two combo boxes. in the left combo select report in place of (General)
    in the right hand combo select NoData in place of Activate

    type
    Cancel = true in between the private sub Report_Open.....
    and End Sub

    then I'd strongly recommend you learn about the Access event model as it will come in handy over the life of this project and as long as you develop with Access
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Nov 2003
    Posts
    300

    Thumbs up

    Well done! Excellent information, I appreciate it. I added a msgbox to let them know they selected a report with no data. It works great. I received no error messages but I am learning more about the error trapping.

    THANKS!

Posting Permissions

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