Separate onChange and afterInsert events (1 Viewer)

aprentice

Registered User.
Local time
Yesterday, 16:30
Joined
Aug 27, 2005
Messages
37
I use the events afterInsert of a Form frmA and the onChange of a field in the same form in order to make some changes to another Form frmB.

Everything goes as expected when the field (with the onChange event assigned) of an existing record changes.
The problem starts when I add a new record which triggers both AfterInsert event (desired) and onChage event (undesired).

Is there a trick to separate the two events?
Basically I want to call a Sub when the data on the field change (onChange)
and a different Sub when I add a new record (AfterInsert).

Thanks in advance
 

RuralGuy

AWF VIP
Local time
Yesterday, 17:30
Joined
Jul 2, 2005
Messages
13,825
The OnChange event should *only* occur after *every* keystroke in the control. I am pretty sure adding a new record should *not* trigger the OnChange event of a control.
 
Last edited:

aprentice

Registered User.
Local time
Yesterday, 16:30
Joined
Aug 27, 2005
Messages
37
RuralGuy said:
The OnChange event should *only* occur after *every* keystroke in the control. I am pretty sure adding a new record should *not* trigger the OnChange event of a control.


Probably you didn't understand that in my form the new Record is added automatically (the form is in datasheet view) when the user types anything in the textbox. That's why both events are tiggered.
 

RuralGuy

AWF VIP
Local time
Yesterday, 17:30
Joined
Jul 2, 2005
Messages
13,825
OK, I had it backwards and you are correct. The OnChange event will occur along with the AfterInsert event on the first keystroke in a control in a new record. Maybe if you describe what you are doing during these different events, we can provide a different solution.
 

aprentice

Registered User.
Local time
Yesterday, 16:30
Joined
Aug 27, 2005
Messages
37
RuralGuy said:
OK, I had it backwards and you are correct. The OnChange event will occur along with the AfterInsert event on the first keystroke in a control in a new record. Maybe if you describe what you are doing during these different events, we can provide a different solution.

Well the afterInsert adds a new record in formB
while the onChange event updates the relative record in formB.
Both event-procedures are implemented with VBA.
 

RuralGuy

AWF VIP
Local time
Yesterday, 17:30
Joined
Jul 2, 2005
Messages
13,825
So you are sort of "running" two forms at the same time? Are they layed out on the screen so the user can see both update at the same time? Why the OnChange event rather than the AfterUpdate event of the control? Surely FormB could wait 'til the user is done with that control. Do you really need to adjust FormB after *every* keystroke?
 

aprentice

Registered User.
Local time
Yesterday, 16:30
Joined
Aug 27, 2005
Messages
37
RuralGuy said:
So you are sort of "running" two forms at the same time? Are they layed out on the screen so the user can see both update at the same time? Why the OnChange event rather than the AfterUpdate event of the control? Surely FormB could wait 'til the user is done with that control. Do you really need to adjust FormB after *every* keystroke?

You are right, in fact the they are subforms on a main form.
I am not very familiar with the afterUpdate event but could it solve my problem?
I mean, as far as I know, afterUpdate fires after a record is updated or added. So it will also conflict with the procedure called by afterInsert event.
 

aprentice

Registered User.
Local time
Yesterday, 16:30
Joined
Aug 27, 2005
Messages
37
RuralGuy said:
So you are sort of "running" two forms at the same time? Are they layed out on the screen so the user can see both update at the same time? Why the OnChange event rather than the AfterUpdate event of the control? Surely FormB could wait 'til the user is done with that control. Do you really need to adjust FormB after *every* keystroke?

You are right, in fact the they are subforms on a main form.
I am not very familiar with the afterUpdate event but could it solve my problem?
I mean, as far as I know, afterUpdate fires after a record is updated or added. So it will also conflict with the procedure called by afterInsert event.
 

aprentice

Registered User.
Local time
Yesterday, 16:30
Joined
Aug 27, 2005
Messages
37
In the Access World Forums > Microsoft Access Discussion > Forms subboard
I can see that the last post was from you (RuralGuy)
but when I open the topic I can't find it.
What's wrong?
 

RuralGuy

AWF VIP
Local time
Yesterday, 17:30
Joined
Jul 2, 2005
Messages
13,825
The AfterUpdate event of the Control fires when the user moves to a different Control. I don't believe the Form has an OnChange event so you have been dealing with the OnChange event of a Control. Just move your code to the AfterUpdate event of *that* control and see what happens.
 

aprentice

Registered User.
Local time
Yesterday, 16:30
Joined
Aug 27, 2005
Messages
37
RuralGuy said:
The AfterUpdate event of the Control fires when the user moves to a different Control. I don't believe the Form has an OnChange event so you have been dealing with the OnChange event of a Control. Just move your code to the AfterUpdate event of *that* control and see what happens.

Eventually I manage to separate the two event by adding a module-variable which "tells" the onChange (or AfterUpdate) event if the event fired by a new record addition or if the user changed an existing one.
I can provide you with more details if you are interesting in.
 

Users who are viewing this thread

Top Bottom