Control AfterUpdate event runs twice

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    Control AfterUpdate event runs twice

    I am scratching my head over this. I have a combo box control where the afterupdate event or even the onchange event keeps runnning twice.

    Below is some simple code to emulate the problem I am having.

    Assume combobox control is cboTest and command button control is cmdTest.

    [code=vb]
    Private Sub cboTest_AfterUp date()
    MsgBox ("Change")
    End Sub

    Private Sub cmdTest_Click()
    Me.cboTest.SetF ocus
    Me.cboTest.List Index = Me.cboTest.List Index - 1
    End Sub

    [/code]

    Assume the combo box is populated with 3 text strings (whatever you want). If I make a selection using the combobox then the afterupdate event triggers once (like I want it to). If on the other hand I click on the command button it should select the previous item in the combo box.

    All of this works except when I use the command button all the code in the afterupdate event of the combobox runs twice.

    Any ideas what I am doing wrong or not understanding?

    (Note code simplified for demonstration purposes - Note you must first select the 2nd or third item before clicking on the command button for this simple code to work. - it still fails with this simple code) - Using Access 2007

    cheers,
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hello, mshmyob.

    I woud not worry too much about the reasons of that behavior and code it to change combobox via Value property which doesn't trigger AfterUpdate at all.

    Something like:
    Code:
    .Value = .Column(.BoundColumn - 1, .ListIndex - 1)
    If AfterUpdate handling is desired, then you could call it explicitely.

    Regards,
    Fish

    Comment

    • missinglinq
      Recognized Expert Specialist
      • Nov 2006
      • 3533

      #3
      Truly odd behavior! As Fish has said, if you simply assign a Value to the combobox, the AfterUpdate event doesn't fire at all. Events should as BeforeUpdate and AfterUpdate are only supposed to fire when you physically change the data, not when you do it thru code.

      Linq ;0)>

      Comment

      • mshmyob
        Recognized Expert Contributor
        • Jan 2008
        • 903

        #4
        Thanks Fish, Linq. I had to change it to the way you guys said unfortunatley it meant I had to put in explicite calls in 4 different places for 4 command buttons.

        It would be nice to just have it in one place in the after update event.

        Oh well. Thanks again.

        cheers,

        Comment

        Working...