473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Control AfterUpdate event runs twice

mshmyob
904 Expert 512MB
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
3 4432
FishVal
2,653 Expert 2GB
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
3,532 Expert 2GB
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
904 Expert 512MB
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

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

Similar topics

5
by: Scott | last post by:
I have created a form that has a few combo boxes on it. On the form I have ComboBoxA which selects data from a region, and ComboBoxB that selects individual locations within a selected region. I...
2
by: Jason G | last post by:
** Any assistance you can provide would be greatly appreciated ** I have a main form with multiple sub-forms. On the main form, I have a checkbox that corresponds with each sub-form, and this...
3
by: Joshua Ammann | last post by:
Hi, (Using Access 2000) I have two tables, similar to Customers and Orders. (Not an exact parallel, but works for this example.) On a form showing customer data, there is a tab control. One...
2
by: jv | last post by:
Hello, I have a Service Cancellation form that contain a CancelDate text box. The text box has an AfterUpdate event that perform a few calculations. This works fine. However, next to the text...
7
by: vindaloo1 | last post by:
I'm using Access 2000 and I have a main form and a subform. When a control on the subform is updated I am trying to update a control on the mainform. But instead of updating the control on the...
6
by: Michael Johnson Jr. | last post by:
I am trying to handle a button click event, which updates a web control table with data. The button is dynamically created in the table itself. When I call updateTable() in the Page_Load the new...
2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
13
by: PW | last post by:
Hi, This is bizarre. I've check and rechecked the spelling, cut and paste the name of the form (when trying to rename the form) and the control yet I still get a parameter prompt when the form...
3
by: =?Utf-8?B?QmFycnkgR2lsYmVydA==?= | last post by:
I have a class that raises events that downstream objects subscribe to. In one case, after destroying the object, the event seems to still get handled in a subscriber object. So I instantiate an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.