BeforeUpdate or AfterUpdate Events

T

Ted

am using a2k in case it matters.

i was pretty convinced what i was wanting was to write this vba in the
AFterupdate event of the form's. what i'm trying to do is test if the user
has made any changes to the controls spelled out in the code and if so in at
least one of the instances i list then launch a macro which updates a table
with the updated value or values of the said controls. it doesn't appear to
be happening. in testing it with the breakpoints, i notice that if i, say,
change the value of 'Campus', allowing the other ones to remain as before,
and attempt to move to the next record, the value of Flag remains at 0.

i thought that the afterupdate event occurs after changed data to a control
or record is updated (to quote the pertinent documenation). how have i run
afoul of vba this time :-(


Private Sub Form_AfterUpdate()
Dim Flag As Integer

Flag = 0

Select Case Outcome_

Case 5, 6, 7

If Me.Last_Name <> Me.Last_Name.OldValue Then
Flag = Flag + 1
ElseIf Me.First_Name <> Me.First_Name.OldValue Then
Flag = Flag + 1
ElseIf Me.MR_Number <> Me.MR_Number.OldValue Then
Flag = Flag + 1
ElseIf Me.SequenceNum <> Me.SequenceNum.OldValue Then
Flag = Flag + 1
ElseIf Me.SponsorIDNumber <> Me.SponsorIDNumber.OldValue Then
Flag = Flag + 1
ElseIf Me.IRB_Number <> Me.IRB_Number.OldValue Then
Flag = Flag + 1
ElseIf Me.OffStudyDate <> Me.OffStudyDate.OldValue Then
Flag = Flag + 1
ElseIf Me.Campus <> Me.Campus.OldValue Then
Flag = Flag + 1
End If

Case Else

End Select

If Flag > 0 Then DoCmd.RunMacro "Update Screening Log (Edit Only) Record"

End Sub
 
B

Brendan Reynolds

It's too late to examine the OldValue property in the AfterUpdate event
procedure. It has been reset by the time the AfterUpdate event is fired. You
need to examine it in the BeforeUpdate event procedure instead.
 
T

Ted

Are you saying to basically carve this out of the AU event and plonk it into
the BeforeUpdate event?
 
B

Brendan Reynolds

I have not tested your code, so I can not guarantee that it will work in the
BeforeUpdate event procedure, but I can guarantee that it will *not* work in
the AfterUpdate event procedure. In the AfterUpdate event procedure, the
Value and OldValue properties will always be equal.
 
T

Ted

brendaan,

my code works! thanks to your idea :)

it'd be kind of interesting to learn why the oldvalue isn't available in the
AfterUpdateEvent for testing purposes because it doesn't get reflected as
having gotten changed when it does, but i'll also settle for working code.

best,

-ted
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top