Results 1 to 8 of 8
  1. #1
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    NoData Event Procedure (2000 SR1)

    Is there a way to create a global "NoData Event Procedure" for all reports in a database or does the procedure have to be entered into each report?

    Tom

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Sint Niklaas, Belgium
    Posts
    2,778
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: NoData Event Procedure (2000 SR1)

    You can write your function in a module.
    In property window in the OnNodata event enter :
    =MyNoDataFunction()
    to invoke your function
    Francois

  3. #3
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: NoData Event Procedure (2000 SR1)

    Thanks.

    Tom

  4. #4
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: NoData Event Procedure (2000 SR1)

    As you can tell, I am a beginner.
    
    When I used an [EventProcedure] in the On No Data property and created a Private Sub,

    Private Sub Report_NoData (Cancel As Integer)
    Msgbox "My Message"
    Cancel = True
    End Sub

    this method works fine.

    In a Module, I created
    Public Function MyNoDataFunction (Cancel As Integer)
    Msgbox "My Message"
    Cancel = True
    End Function

    On NoData property I entered
    =MyNoDataFunction()

    When I run the report, I get an error message:

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

    Re: NoData Event Procedure (2000 SR1)

    In the first place, omit the Cancel argument from the function.

    In the second place, use DoCmd.CancelEvent instead of Cancel = True.

    Public Function MyNoDataFunction()
    Msgbox "My Message"
    DoCmd.CancelEvent
    End Function

    The way you call the function in the OnNoData event is correct.

  6. #6
    4 Star Lounger
    Join Date
    May 2002
    Location
    Roanoke, Virginia, USA
    Posts
    493
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: NoData Event Procedure (2000 SR1)

    My thanks. It works perfectly.

    Tom

  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: NoData Event Procedure (2000 SR1)

    Hi Hans

    I see the value of moving common form and report code to modules, when would you move the module to a class module?

    What are the advantages of class modules over modules?

    Thanks, John

  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 Procedure (2000 SR1)

    Class modules are wrappers around the ugly details of what goes on inside a class. It's perfectly possible to build a clsForm class module that contains form code or a clsRpt class module that contains report code, and I do that quite a bit.

    When you move the code to a standard module, you can call the routines from any form or report and pass in the appropriate object reference so the code knows what it's working on. With a class module, you bind each object itself to its particular class in the object's open event, and the class automatically knows what object it's working with. There are catches of course, and one catch is that an unhandled error in your code will break the connection to your class object, usualy leaving you in a much worse situation than if the error occurred in a standard module. Another is that you can't just call a routine from a class. You have to instantiate the class and then use its methods and properties to do what you want. That may be overkill unless there are a bunch of other things you want the class to do for you.

    The biggest advantage to an object class is that all you have to do is make sure you bind the object to the class. I usually add a test in the Current event as well, to rebind the object if something has broken the connection. (Never happens, of course. <img src=/S/liar.gif border=0 alt=liar width=25 height=22> ) After that, the class takes care of making your object behave the way you want it to. Unfortunately, if you have a class for forms, you probably also need a class for each kind of control you want to influence and those have to be bound as well, to each control on the form or report.
    Charlotte

Posting Permissions

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