By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,476 Members | 1,376 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,476 IT Pros & Developers. It's quick & easy.

Control AfterUpdate event runs twice

mshmyob
Expert 100+
P: 903
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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub cboTest_AfterUpdate()
  2.     MsgBox ("Change")
  3. End Sub
  4.  
  5. Private Sub cmdTest_Click()
  6.     Me.cboTest.SetFocus
  7.     Me.cboTest.ListIndex = Me.cboTest.ListIndex - 1
  8. End Sub
  9.  
  10.  
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,
Feb 2 '09 #1
Share this Question
Share on Google+
3 Replies


FishVal
Expert 2.5K+
P: 2,653
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:
Expand|Select|Wrap|Line Numbers
  1. .Value = .Column(.BoundColumn - 1, .ListIndex - 1)
  2.  
If AfterUpdate handling is desired, then you could call it explicitely.

Regards,
Fish
Feb 2 '09 #2

missinglinq
Expert 2.5K+
P: 3,532
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)>
Feb 2 '09 #3

mshmyob
Expert 100+
P: 903
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,
Feb 2 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.