Change in a field does not trigger "afterupdate" event (1 Viewer)

mafhobb

Registered User.
Local time
Today, 08:37
Joined
Feb 28, 2006
Messages
1,245
Hi all,

I've got a form with several fields that get updated regularly. These fields have a "Before Update" event that changes the value of another field (called "DateModified")

Code:
Private Sub Rudder_3D_Rate_BeforeUpdate(Cancel As Integer)
    On Error GoTo BeforeUpdate_Err
    
    'Set bound controls to system date
    DateModified = Date
BeforeUpdate_End:
    Exit Sub

The "datemodified" fields basically gets updated every time one of the original fields gets modified, so that way I know when the change was made. This works well and I can see how the "datemodified" field changes immediately after any original field is modified.

To add more functionality to the database, I am now trying to send an automatic e-mail to the people who needs to get notified of the change. First, however, I just want to get a message box to verify that the code works so I have added the following code to the "afterupdate" event to the "datemodified" field:

Code:
Private Sub DateModified_AfterUpdate()
MsgBox "Need to send e-mail to PS"
End Sub

However, nothing happens. I can see the "datemodified" field getting modified, but the message box does not show up. I have tried adding this to a "change" and "beforeupdate" events, but nothing...

What is happening? Why are these events being ignored even when the field does get automatically updated?

Help would be greatly appreciated...I have been scratching my head for a while...

mafhobb
 

DCrake

Remembered
Local time
Today, 14:37
Joined
Jun 8, 2005
Messages
8,632
The on change and afrter update only apply if the said control has the focus, in your case it doesn't. You need to do something with the control that performs the origninal update.

David
 

mafhobb

Registered User.
Local time
Today, 08:37
Joined
Feb 28, 2006
Messages
1,245
I see.

I can do that. I have 39 fields that cause the "datemodified" to change. Is there any way to simplify what I need to do instead of adding the same piece of code (send e-mail to such and such people) to all 39 fields?

mahobb
 

DCrake

Remembered
Local time
Today, 14:37
Joined
Jun 8, 2005
Messages
8,632
If you are using a bound form then you could use the OnCurrent event to compare the original value tothe current value and respond accordingly. I Think. Don't use bound forms much.

Maybe someone else has a better solution.

David
 

Insane_ai

Not Really an A.I.
Local time
Today, 09:37
Joined
Mar 20, 2009
Messages
264
You could use a subroutine and call it every time you have an update.
 

mafhobb

Registered User.
Local time
Today, 08:37
Joined
Feb 28, 2006
Messages
1,245
Hi Insane,

I think I like the subroutine solution better. I do not have much experience with them, though.

Do you know of any place I can find a good example?

mafhobb
 

mafhobb

Registered User.
Local time
Today, 08:37
Joined
Feb 28, 2006
Messages
1,245
If I understand this I need to:

1- Create a class module for the form that contains the code that I need. Let's call that module "Specs Update". I assume the code needs to start with "public sub e-mail" or something similar
2- Call the "e-mail" sub in the afterupdate event of the fields that update the "datemodified" field.

Am I in the ballpark (This will be my first module...)?

mafhobb
 

mafhobb

Registered User.
Local time
Today, 08:37
Joined
Feb 28, 2006
Messages
1,245
..or...

Should I just add a "public sub" at the end of the code for that form and then simply call that sub form anywhere in that code?

Can I do that?

mafhobb
 

WIS

Registered User.
Local time
Today, 23:37
Joined
Jan 22, 2005
Messages
170
I see.

I can do that. I have 39 fields that cause the "datemodified" to change. Is there any way to simplify what I need to do instead of adding the same piece of code (send e-mail to such and such people) to all 39 fields?

mahobb

Use the Dirty method and the BeforeUpdate event of the form.

If Me.Dirty Then
Me.DateModified = Date
End If

Before and AfterUpdate events:

The recordsource of the form is available to the Form BeforeUpdate event but not to the Form AfterUpdate event.

ie BeforeUpdate: The following works

If Me.Dirty Then
Me.DateModified = Date
End If

AfterUpdate: The above will not work.
 

SOS

Registered Lunatic
Local time
Today, 06:37
Joined
Aug 27, 2008
Messages
3,517
If you use the Before Update event of the form you do NOT have to test to see if the form is dirty. The Before Update event ONLY fires if the form has been "dirtied."
 

Insane_ai

Not Really an A.I.
Local time
Today, 09:37
Joined
Mar 20, 2009
Messages
264
Hi Insane,

I think I like the subroutine solution better. I do not have much experience with them, though.

Do you know of any place I can find a good example?

mafhobb


Public Sub Update_Mod_Stamp
[DateModified] = Date
MsgBox "Need to send e-mail to PS"
End Sub
On the individual controls, paste Update_Mod_Stamp
If you do not get results, change sub to function. By definition, the Function in this case is incorrect to use because you are not returning a value but sometimes Access just needs it to give you what you want.
 

mafhobb

Registered User.
Local time
Today, 08:37
Joined
Feb 28, 2006
Messages
1,245
Hey, that worked.

I've got it!

Thanks for all the help

mafhobb
 

Users who are viewing this thread

Top Bottom