473,657 Members | 2,576 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Control AfterUpdate event runs twice

mshmyob
904 Recognized Expert Contributor
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 4456
FishVal
2,653 Recognized Expert Specialist
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 Recognized Expert Specialist
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 Recognized Expert Contributor
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
39602
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 need to figure out the correct way to Requery ComboBoxA after I have updated it. I searched the archive for this list and found a simple solution: put Me.Requery in the AfterUpdate event of ComboBoxA. However, when I try this I get an error...
2
7600
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 checkbox will express the users desire to lock the ability to edit a corresponding sub-form. To do this, I figure that each checkbox will have : (1) the AfterUpdate property call a Macro or VB Module to execute the setting of the Allow Edits...
3
4138
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 of the tabs has a subform showing order data (in datasheet view). On the same tab there is an unbound textbox (next to the datasheet). I placed a
2
1941
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 box is a calendar button that would allow users to select a date using a pop calendar form. This calendar form works great except that I want the textbox's afterupdate event to run after a date has been selected using the popup form. So what did...
7
2050
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 main form's current record, it updates the main form's control on every record. This is the code I'm using for this: Set cnn = CurrentProject.Connection strSQL = "SELECT SUM(AmountPaid)AS SumAmountPaid FROM BillPayments WHERE " & _
6
2839
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 data from the button is not available at this time as to allow the table to properly update. So basically, I need to call UpdateTable() twice, once from page load and once from button. This causes problems with my application, and I was trying...
2
2918
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 a WebForm with some textboxes, dropdownlists, a panel, imagebutton and so on. When I click on the image button (which was created at design time) I dynamically build a table. In each of row of that new table I put several cells and one cell...
13
1987
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 runs. I've even deleted the control and started over. This is the code for the recordsource of the form: "SELECT * FROM qryGuestStorePurchases_pw WHERE
3
1562
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 object and the event fires correctly. Then I destroy the object and instantiate another instance and the subscriber event handler get hit twice. I've tried using IDisposible and also using GC.Collect, but it didn't seem to help. I've also tried...
0
8392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.