Results 1 to 8 of 8
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Reference a rpt OnNoData Event's Cancel Argument (2002/SR1)

    I want to avoid having modules behind each one of my reports. Is it possible to reference a reports On No Data's cancel argument from a Standard Module?

    Thanks in Advance for any help.
    Don

  2. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: Reference a rpt OnNoData Event's Cancel Argument (2002/SR1)

    Don't you mean Event code instead of modules?
    You could test (by Dcount) if the reports underlying query has a count of zero to establish if a NoData condition exists.
    What's the problem with putting code into the OnNoData event of these reports?
    Pat <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Reference a rpt OnNoData Event's Cancel Argument (2002/SR1)

    Technically what you are referring to is a class module that is associated with a report. In 2002 you can have light versions of forms and (I believe) reports, but in our experience there is almost no difference in performance, and if you put the code into a regular module, it will always be loaded so your Access memory footprint gets larger. In addition, you can't reference the NoData cancel argument, so my advice would be to use the simple NoData code and be done with it.
    Wendell

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

    Re: Reference a rpt OnNoData Event's Cancel Argument (2002/SR1)

    You could reference it from a class module, but you would still need a module behind the report before you could trap its events.
    Charlotte

  5. #5
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reference a rpt OnNoData Event's Cancel Argument (2002/SR1)

    Thanks for your reponse Wendell!

    I was just assuming there would be a slight performance hit on creating modules behind all of my reports. Thanks for the insight.

    Don

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Reference a rpt OnNoData Event's Cancel Argument (2002/SR1)

    For simple reports that require no other code, I often use a set of functions in a standard module:

    Function DoMaximize()
    [tabDoCmd.Maximize
    End Function

    Function DoRestore()
    DoCmd.Restore
    End Function

    Function EmptyReport()
    MsgBox "There are no data for this report.", vbExclamation
    DoCmd.CancelEvent
    End Function

    The reports have no module; I enter the functions in the Properties window, Events tab, as follows:

    <table border=1><td> On Close</td><td> =DoRestore()</td><td> On Activate</td><td> =DoMaximize()</td><td> On Deactivate</td><td> =DoRestore()</td><td> On No Data</td><td> =EmptyReport()</td></table>

    This has little or no advantage if you have one or two reports, and it doesn't help at all if you need a module behind the report for other code. But if you have lots of simple reports, having one standard module instead of modules for each report will result in a smaller database. I don't think performance is significantly better in either situation.

  7. #7
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Portland, Maine, USA
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Reference a rpt OnNoData Event's Cancel Argument (2002/SR1)

    Yes, most of my reports are simple and for those I was just going to have one Standard module with the function name in the appropriate event like you suggested. I just wasn't sure how you could use the cancel event for a report that has no data. So the DCmd.CancelEvent will do the trick huh? I will give it a shot!

    Thanks again!
    Don

  8. #8
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: Reference a rpt OnNoData Event's Cancel Argument (2002/SR1)

    Ah - I was having a slow day - Hans has neatly solved your problem and it should work like a charm. I had forgotten that you can cancel an external event with the CancelEvent method. Well done Hans! <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>
    Wendell

Posting Permissions

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