Firing off the AfterUpdate event procedure from VBA

Maximation

Registered User.
Local time
Today, 07:39
Joined
Jan 14, 2005
Messages
14
Hello,

I have an "After Update" event procedure for a field on a form that calls a VBA sub. When I use a different VBA sub to input a value in the above mentioned field, the "After Update" event does not occur, even thought the data in the field has been changed. (Of course if I manually enter the data, the field "After Update" event works.)

Is there a flag or condition that needs to be set in my VBA sub to let the field realize that it has been changed? Or possible a way to call the fields AfterUpdate Sub?

I tried having a my sub call the AfterUpdate sub to see what would happen, but didn't get it to work. I got a bunch of error and didn't feel like this was really the way to go.

I also could just duplicate all the code in the AfterUpdate sub for the field, but we all know that that is not a good idea.

Thank you for any help.
 
Your observations are correct, that the AfterUpdate event doesn't fire for a control if you programatically change that control's data.

But this line of code will run the following sub...

someControl_AfterUpdate

Private Sub someControl_AfterUpdate()
'after update code
End Sub
 
While calling the control's AfterUpdate event will execute it, that won't save the changed value. A better solution is to force the form to save the current record. That will automatically execute both the BeforeUpdate and AfterUpdate events of the control and the form.

DoCmd.RunCommand acCmdSaveRecord
will save the current record.
 
Does:
Me.Refresh = DoCmd.RunCommand acCmdSaveRecord
?
 
No. They are not equivalent although refresh MAY cause the current record to be saved. I know that Requery causes the current record to be saved but it also has unwanted side effects.
 
Hi,

lagbolt-
Your suggestion work nicely, thank you. I see were I was going wrong when trying to do this earlier. I was calling the sub like it was a function().

Pat Hartman-
Your suggestion was a good Idea to save the record, thank you. Although this saved the record, for some reason, it did not fire off the Before_Update or After_Update event as you had mentioned. If it was supposed to, I don't know why it didn't? I know enough about access and VBA to get by, but I would love to find a good book or something that dives very deep into the coding side.

I ended up using both your suggestions together. I don't think that I should have any bad side effects from doing this.

Thanks again.
 

Users who are viewing this thread

Back
Top Bottom