473,418 Members | 1,749 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,418 software developers and data experts.

Combobox AfterUpdate Bizarre

23
This is bizarre... Im having problems with the combobox AfterUpdate event:

Im running Access 2003.

I created an unbound combobox with 3 columns on a form.
The Row Source is from a table.
Bound Column = 1 and LimitToList = No,,, thus the user can edit the data in the 1st-Column after they selected one of the rows in the combobox.

However, I want to save the data of 2nd-Column and 3rd-Column, because if the user edits the 1st-column, the resulting text might not be in the Row Source, which will result in 2nd-Column and 3rd-Column to go blank.

I thus created two text boxes (TextA and TextB) to store the values of 2nd-Column and 3rd-Column each time the user selects a row from the combobox.

I entered the following code for the Combobox's AfterUpdate event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub InvoiceDetailCombo_AfterUpdate()
  2.     TextA = [Forms]![Mainform1]![InvoiceDetailCombo].[Column](1) '2nd-Column
  3.     TextB = [Forms]![Mainform1]![InvoiceDetailCombo].[Column](2) '3rd-Column
  4.     MsgBox "After Update" 'Just to make sure the event fires
  5. End Sub
Now, if I select a row in the Combobox. Everything works fine. The data is copied to TextA and TextB and my little "After Update" message pops up.

Then I edit the text in the Combobox.
When I click the mouse on another control, the new edited data in 1st-Column is not found in the Row Source, which results in blanks/nulls being copied to TextA and TextB and the "After Update" message is displayed. Everything OK so far.

But, if I ever-so-lightly click on another control after the 1st-Column's data was edited (as if the combobox only lost focus), the "After Update" message still appears but this time no data is copied to TextA or TextB (you can even test the values of TextA and TextB with a query - they still have their old values).

It appears that the pressure of your finger on the mouse button influences something. However it does not look as if the entire AfterUpdate event was skipped, because my little message still came up - yet TextA and TextB were left unchanged.

It also works the same if you press the right-mouse-button.

What is more... they way the text in 1st-Column was edited also has an influence.
If text is added, TextA and TextB are left unchanged. But if some of the text is deleted, TextA and TextB are updated every time - regardless of left or right button or finger pressure.

I'm dumb folded
Gerhard
Sep 22 '08 #1
12 5414
hjozinovic
167 100+
Do you have any code in OnCurrent event of the form that holds the controls?
This code might be your problem....
Sep 22 '08 #2
Gerhard
23
Hallo

Yes, I have quite a lengthy peace of code in the main form's On Current event, but that is not the problem, because I copied the combobox and the two text boxes to a new blank form with nothing else on it. But the problem keeps on repeating itself.

Must I email you a copy of the mdb with everything removed except for this one little form and the small table for the combobox's Row Source?

I got a tip somewhere in a forum to move all my combobox's code from the After Update event to the On Lost Focus event. This seems to have done the trick. Still, maybe lots of people don't know that their comboboxes' AfterUpdate events work sometimes and sometimes not.

Gerhard
Sep 23 '08 #3
NeoPa
32,556 Expert Mod 16PB
The trick is to put the code you want to run after a successful update into the AfterUpdate event procedure, and the code you want to run whenever the control loses focus, in the LostFocus event procedure.
Sep 23 '08 #4
Gerhard
23
Yes, but the problem is that it appears that not all the code in the AfterUpdate event executed after a successful update.
Sep 23 '08 #5
NeoPa
32,556 Expert Mod 16PB
Did you do any debugging (using tracing of code - See Debugging in VBA) when this happened? If so, what did you discover?
Sep 23 '08 #6
Gerhard
23
I'm able to see the value of my combobox's 1stColumn in the "Locals" pane under "Oldvalue" and "value", but I can't find the values of the 2nd and 3rdColumns. Where must I look?
Sep 23 '08 #7
Gerhard
23
Found it under recordset > Items. Will come back.
Sep 23 '08 #8
NeoPa
32,556 Expert Mod 16PB
Good for you. Did you find that link helpful?
Sep 23 '08 #9
Gerhard
23
Yes thanks. Why haven't anybody give you credit for it yet? Well done!

OK here is where I am:

Sorry to say but I'm now even a bit more confused.
You must see this to believe it.

I have eliminated everything in the mdb and reduced the combobox to only two columns to try to keep everything as simple as possible and I have left only one textbox called TextA. The idea is that when the user selects a row in the combobox, the data in the combobox's 2nd column must be copied to TextA.

It is very straightforward. My only code on the entire form is this:
Expand|Select|Wrap|Line Numbers
  1. Private Sub ComboTest_AfterUpdate()
  2.     TextA = Eval("[Forms]![Form1]![ComboTest].[Column](1)")  '2nd Column
  3. End Sub
  4.  
In the debugger's locals pane I found the combobox referred to as Item 1.
Under Item 1, I found Record set > Fields > Item 1 and Item 2, which I take is the 1st and 2nd columns of the combobox.

I set a breakpoint before TextA = Eval.....

When I select a row in the combo box, it works fine and the value of the 2nd Column is copied to TextA. Even if the debugger pops up and I press F8 through the steps, everything looks fine.

But, if the debugger pops up and I first go into the locals pain to see the values in Item 1 >Record set > Fields > Item 1 and Item 2, I find the combobox's list's first row's data in these fields and subsequently this wrong data is also copied to TextA.

Thus, this correlates with my previous problem which is: the moment that the combobox's update is sort of "interrupted" it does strange things.

Maybe I should mail you the mdb. It is very small (0.3 meg).
Sep 23 '08 #10
NeoPa
32,556 Expert Mod 16PB
Gerhard, I missed this reply earlier, and was lucky to find simply by looking through some old emails when I found the one for your posting this on Monday. Lucky, as otherwise I might have missed this thread altogether until you'd posted again sometime.

Let me see if I can add a few helpful comments (hints) as I go through your post.
Expand|Select|Wrap|Line Numbers
  1. Private Sub ComboTest_AfterUpdate()
  2.     TextA = Eval("[Forms]![Form1]![ComboTest].[Column](1)")  '2nd Column
  3. End Sub
Eval is not required, and [] around Column is incorrect. Try instead :
Expand|Select|Wrap|Line Numbers
  1. Private Sub ComboTest_AfterUpdate()
  2.     TextA = Me.ComboTest.Column(1)  '2nd Column
  3. End Sub
Item1 & Item2 in the debugger (under Fields) would refer to separate, individual fields within your datasource, the recordset.
In the debugger's locals pane I found the combobox referred to as Item 1.
Under Item 1, I found Record set > Fields > Item 1 and Item 2, which I take is the 1st and 2nd columns of the combobox.

I set a breakpoint before TextA = Eval.....

When I select a row in the combo box, it works fine and the value of the 2nd Column is copied to TextA. Even if the debugger pops up and I press F8 through the steps, everything looks fine.

But, if the debugger pops up and I first go into the locals pain to see the values in Item 1 >Record set > Fields > Item 1 and Item 2, I find the combobox's list's first row's data in these fields and subsequently this wrong data is also copied to TextA.
It's hard to understand exactly what is happening here, but I would guess that doing this without debugging doesn't have the problem. If so, then there is nothing to worry about I guess. The (Column()) code does depend on which row of the ComboBox is currently selected. If you do something which changes that before the code is run then the code will reflect this change, as you describe.
Maybe I should mail you the mdb. It is very small (0.3 meg).
I don't see a need for that at this time. If we get to that point (I'd rather avoid it personally), then you can zip up the file and attach it to a new post in this thread.
Sep 23 '08 #11
Gerhard
23
I Guess the best way to go forward is to avoid comboboxes where LimitToList = No. Thus way the combobox always find a valid row in it's list, which ensures that the AfterUpdate event runs smoothly.
Sep 24 '08 #12
NeoPa
32,556 Expert Mod 16PB
That wouldn't be (wasn't) my advice. I would endeavour to find the fundamental problem then fix, or work around, that.
Sep 24 '08 #13

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

Similar topics

5
by: Steve | last post by:
I have an unbound combobox in the form header of a continuous form. The selection in the combobox sets the where clause in a querydef which determines QryPFrmInventoryManagement. The following code...
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
3
by: rmatteson | last post by:
I am trying to figure out how to clear all items from a combobox (Access 2002). On my form, I have to comboboxes. Combobox 2 is populated with a set of child data dependent on the parent data...
3
by: jim | last post by:
Hi NG I have a form in which I use a combobox - the content of the combobox depend on the customername shown in a textbox. Now my problem is that I want the content in the combobox to change...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
12
by: eetarnold | last post by:
Hi Gurus, As I've read in other posts the past couple of days, I've read many great posts and haven't figured out how I can solve this problem...I'm trying to make a form very user friendly for...
17
by: ApexData | last post by:
Hello I have a single form, and want to require the user to make a selection from a serialnumber ComboBox before being allowed to enter any other textboxes. Also, the user should be allowed to...
3
by: ApexData | last post by:
COMBOBOX REFRESH DILEMMA ' I have been working for hours trying to figure out how to requery a combobox in a subform, from a Popup form ' that this subform had launched. Basically, I designed...
1
by: nico3334 | last post by:
I would like to use the AfterUpdate option for a combobox in VB6. When the user selects a different item from the combobox, I want a label's caption to change. I accomplished this in VBA, but I...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
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.