'Before update' event triggering

D

Dorian

I have some code which checks if a record has been emailed.
The check is triggered whenever I move to a new record.
I have the check in the 'before update event'
When the user clicks the 'email' button, I have to do a save to ensure any
pending record changes are saved before I generate the email. This in turn
triggers the 'before update' event.
I am then in a situation where the user has clicked 'email' but then
receives a prompt that he has not emailed yet. I dont want to show the prompt
if it results from clicking 'email'.
How can I arrange this better so I don't have this problem? Thanks.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
P

PJFry

I need a little clarification. It sounds like you have two before update
events. One on the form level (...The check is triggered whenever I move to
a new record.
I have the check in the 'before update event'
....) and one on the click level for you command button (When the user clicks
the 'email' button...This in turn
triggers the 'before update' event.). Is that correct? Or is there just a
before update on the click?

Assuming it is on only the click, you can do a DLookup for the value of the
e-mail on your click event. It would read something like this:

If IsNull(DLookup("emailFlag","table","recordID = " & Me.ID) Then
Send the e-mail
Record e-mail sent
Else
Msgbox that message has already been sent
End If

Just replace the DLookup items with the ones that correspond to your table.

Does that make sense?
 
J

John W. Vinson

I have some code which checks if a record has been emailed.
The check is triggered whenever I move to a new record.
I have the check in the 'before update event'
When the user clicks the 'email' button, I have to do a save to ensure any
pending record changes are saved before I generate the email. This in turn
triggers the 'before update' event.
I am then in a situation where the user has clicked 'email' but then
receives a prompt that he has not emailed yet. I dont want to show the prompt
if it results from clicking 'email'.
How can I arrange this better so I don't have this problem? Thanks.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".

Please post your code.
 
D

Dorian

Before I execute my Email function I do:
If Me.dirty then me.dirty = false
to save any pending changes
This triggers the Before Update event.

Its perfectly ok to email a record more than once but I need to issue a
reminder on records created but not emailed. I do not want the reminder to
appear when they are in the process of emailing (ie. when they click the
email button)
Hope this makes sense.
-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
D

Dorian

Its not feasible to post all the code. It's thousands of lines and intermixed
with other code that has nothing to do with this issue.
Basically when a record is created but not emailed, I display a
Yes/No/Cancel message box. If the user clicks No, I save a 'need to email'
reminder record in a table. This is all done in the BeforeUpdate event.

The problem is that the BeforeUpdate event is also triggered when I actually
do the email as I have to do a
If me.dirty then me.dirty = false
beforehand to ensure all pending changes are saved.
This in turn triggers the BeforeUpdate event and thus the reminder - which I
don't need since I am already in the process of emailing the record.

-- Dorian
"Give someone a fish and they eat for a day; teach someone to fish and they
eat for a lifetime".
 
J

John W. Vinson

Its not feasible to post all the code. It's thousands of lines and intermixed
with other code that has nothing to do with this issue.
Basically when a record is created but not emailed, I display a
Yes/No/Cancel message box. If the user clicks No, I save a 'need to email'
reminder record in a table. This is all done in the BeforeUpdate event.

The problem is that the BeforeUpdate event is also triggered when I actually
do the email as I have to do a
If me.dirty then me.dirty = false
beforehand to ensure all pending changes are saved.
This in turn triggers the BeforeUpdate event and thus the reminder - which I
don't need since I am already in the process of emailing the record.

Sounds like you need to set some sort of flag in the click event code to tell
Beforeupdate that it's ok. This could be a global variable or (better) an
invisible control on the form. Since you know at this point that the record
has been saved, the BeforeUpdate event could simply set Cancel to True and
return.
 

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