OnChange and AfterUpdate have same behavior?? (1 Viewer)

thardyjackson

Registered User.
Local time
Today, 13:12
Joined
May 27, 2013
Messages
45
I have a form with customer info. When user changes a value in the productChosen combobox, other fields should change. I have experimented with "After Update" and "On Change."

In both situations, I see identical behavior with respect to the underlying table -- the table is getting updated only after I change records. Isn't the "On Change" supposed to change the data in the table once I start typing? I prefer this.

The code I'm using when I run the two experiments:

Code:
Private Sub productChosen_Change()
    Me.statusWelcomeMsg = "Not sent" ' resets statusWelcomeMsg in case welcome msg had been sent already
    Me.price = Me.productChosen.Column(1)
    Me.fee = Me.productChosen.Column(2)
    Me.depositMin = Me.productChosen.Column(3)
    Me.pmtMo1Expected = Me.productChosen.Column(4)
    Me.pmtMo2Expected = Me.productChosen.Column(5)
    Me.pmtMo3Expected = Me.productChosen.Column(6)
    Me.pmtMo4Expected = Me.productChosen.Column(7)
    Me.pmtMo5Expected = Me.productChosen.Column(8)
    Me.pmtMo6Expected = Me.productChosen.Column(9)
End Sub

Code:
Private Sub productChosen_AfterUpdate()
    Me.statusWelcomeMsg = "Not sent" ' resets statusWelcomeMsg in case welcome msg had been sent already
    Me.price = Me.productChosen.Column(1)
    Me.fee = Me.productChosen.Column(2)
    Me.depositMin = Me.productChosen.Column(3)
    Me.pmtMo1Expected = Me.productChosen.Column(4)
    Me.pmtMo2Expected = Me.productChosen.Column(5)
    Me.pmtMo3Expected = Me.productChosen.Column(6)
    Me.pmtMo4Expected = Me.productChosen.Column(7)
    Me.pmtMo5Expected = Me.productChosen.Column(8)
    Me.pmtMo6Expected = Me.productChosen.Column(9)
End Sub
 

spikepl

Eledittingent Beliped
Local time
Today, 22:12
Joined
Nov 3, 2010
Messages
6,142
For illustration, temporarily put

MsgBox me.productChosen

in your change handler and see what happens.

Update:

Better put

debug.print "onchange" & me.productChosen

instead, and see the output in the Immediate Window
 

thardyjackson

Registered User.
Local time
Today, 13:12
Joined
May 27, 2013
Messages
45
The new values populate correctly on the form and in the immediate window. But, I want the table updated immediately. The table isn't getting updated until I change to another record.
 

way2bord

Registered User.
Local time
Today, 13:12
Joined
Feb 8, 2013
Messages
177
The new values populate correctly on the form and in the immediate window. But, I want the table updated immediately. The table isn't getting updated until I change to another record.

Your code is updating all the Form objects, NOT the table data.

Unless you've specifically linked your form to the table already, updating the form through me.ObjectName VBA will only change the visuals on the form - NOT update your data table.
 

missinglinq

AWF VIP
Local time
Today, 16:12
Joined
Jun 20, 2003
Messages
6,420
...The table isn't getting updated until I change to another record...

That's correct! Until the Record is saved, it is not a part of the Table!

You can force a save using either

DoCmd.RunCommand acCmdSaveRecord

or

If Me.Dirty Then Me.Dirty = False

Linq ;0)>
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:12
Joined
Feb 19, 2002
Messages
43,486
Are you clear on why the Change event is inappropriate for this task?

To clarify, the Change event runs as each character is entered. The AfterUpdate event runs only once - when the focus moves out of the control. The Change event is useful if you want to trap keystrokes to prevent the user from entering more than "3" characters or to impose masking of data to ensure it conforms to a particular pattern. In the Change event, you must refer to the current contro's .text property rather than its .value property. So -
If Me.someField.text = "abc" Then
But in the BeforeUpdate event, the code would be -
If Me.someField = "abc" Then
The .value property is the default property and so is normally omitted for conciseness.
 

thardyjackson

Registered User.
Local time
Today, 13:12
Joined
May 27, 2013
Messages
45
Pat -- Now I'm clear. I love this forum. It's really helping me get down the learning curve.
 

Users who are viewing this thread

Top Bottom