Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Defining Events to Fire (2003)

    The following example is taken from OnUndo Property In Access Help
    <pre>Dim ctlLoop As Control

    For Each ctlLoop In Forms(0).Controls
    If ctlLoop.Type = acTextBox Then
    ctlLoop.OnUndo = "[Event Procedure]"
    End If
    Next ctlLoop</pre>


    would the above loop be necessary had you already specified "[Event Procedure]" in the "On Undo" box on the property sheet of all the text boxes on the first form of the current project?

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

    Re: Defining Events to Fire (2003)

    No, you would only need this if, for some reason, you had left the On Undo boxes blank, and only wanted to activate the On Undo event procedures later.

    <img src=/S/whisper.gif border=0 alt=whisper width=29 height=17> The example in the online help seems pretty lame to me, but perhaps I'm missing something

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

    Re: Defining Events to Fire (2003)

    It is possible to cut and paste controls, for instance from the detail section to a header or footer. In that case, the [Event Procedure] setting could be lost for the control even though the code is in the form module. That would be the only instance where setting the value in code would be needed. The more usual use for code like that is in a class external to the form. I agree with Hans, it's a lame example.
    Charlotte

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

    Re: Defining Events to Fire (2003)

    No, it isn't safe to bypass that. If you have an event procedure already, both the existing code, if any, and the code in the public class will execute. I can't remember the order of precedence offhand, but I believe the public class code executes and then the code in the form event. Furthermore, you can set up an event in a public class that is not set up in the form, so don't try to shortcut that code, it's essential. The event procedures specified in the public class exist in the specific instance of the class. What you're doing, in effect, is telling Access that I want to listen for this event in this class. If you skip that, your class won't behave properly.
    Charlotte

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Defining Events to Fire (2003)

    Thank you Charlotte and Hans,
    if you pause this Microsoft Office System Developers Conference 2006 presentation at 01:09:48, you'll see the following code:

    <pre>Public Sub HookupComboBox(ByVal cbo as ComboBox)
    ' Set the textbox to the object that is defined with events
    AccessComboBox = cbo

    ' Make sure that Access will trigger the events you want to listen to
    AccessComboBox.OnChange = "[Event Procedure]"
    AccessComboBox.AfterUpdate = "[Event Procedure]"
    End Sub

    Public Sub HookupCommandButton(ByVal cmd as CommandButton)
    ' Set the textbox to the object that is defined with events
    AccessCommandButton = cmd

    ' Make sure that Access will trigger the events you want to listen to
    AccessCommandButton.OnClick = "[Event Procedure]"
    End Sub</pre>


    Even if you hook the control from managed code, can you avoid specifying "[Event Procedure]" in code as long as the corresponding control has [Event Procedure] specified in its property sheet therefore possibly not needing the two subs above?

Posting Permissions

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