After update event triggered by changing tab

Andy74

Registered User.
Local time
Today, 13:06
Joined
May 17, 2014
Messages
126
Hello,

I have a main form with a subform, which is placed on a tab page of a tab control belonging to the main form.
The main form afterUpdate event should trigger an email notification. I am trying to include in the email notification some information which is placed in the records of the subform. The issue I have is that the when the user clicks on tab page which contains the main form the afterUpdate event of the main form is triggered before the subform is filled by the user. Hence, the notification is sent before filling the subform. Is there a smart way to avoid this?

Andy
 
You use the BeforeUpdate event to ensure data is correct before doing anything.
 
Have you tried triggering your email in the subform afterupdate event?
 
maybe deliberately send the notification by adding a button on the main form.
the button will need to validate if the subform has some data.
 
Have you tried triggering your email in the subform afterupdate event?
it cannot work, because the user will enter several records on the subform. The notification should be sent only after entering records on the suborm and when the users either close the form or save the record on the main form.
 
maybe deliberately send the notification by adding a button on the main form.
the button will need to validate if the subform has some data.
yes, that's the ultimate solution. But I wanted to avoid this because the typical users simply forget to hit the buttom.
 
Yes, and that is why any validation should go in the Before event. Pointless validating after the data has been updated. :(
 
Hello,

I have a main form with a subform, which is placed on a tab page of a tab control belonging to the main form.
The main form afterUpdate event should trigger an email notification. I am trying to include in the email notification some information which is placed in the records of the subform. The issue I have is that the when the user clicks on tab page which contains the main form the afterUpdate event of the main form is triggered before the subform is filled by the user. Hence, the notification is sent before filling the subform. Is there a smart way to avoid this?

Andy
Can you walk through what you expect your USER to do and at what point in the USER experience the email needs to be sent?
I am guessing "User goes in to parent form and creates/updates/selects parent record. User then goes in to subform and creates one or more child records. User then needs to do SOMETHING that actually commits everything and says 'DONE' to go to the next parent record". What is the condition that is "Done"?
That is the point you create the email. Unless you walk us through exactly how you know they are 'DONE' and the email needs be sent, we won't be able to give you the best answer.
 
If it needs sending when the form closes, why not use the forms close or unload event? (I may be missing something....)
 
yes, that's the ultimate solution. But I wanted to avoid this because the typical users simply forget to hit the buttom.
If the users don't click on the button, maybe you can then "click it" for them. For example, when the form or the app closes (or opens), you can run a procedure to check if there were any emails that needed to be sent and then send them at that time. Just a thought...
 
the problem is that BeforeUpdate triggers before the AfterUpdate, hence the problem is always there

Technically, no. The actual act of updating triggers the BeforeUpdate and AfterUpdate events, but there is no visible Update event. That particular event is purely internal to Access itself. And the main form's update occurs when you return to the main form after updating one or more records in the sub-form. When you activate the main form after exiting a "dirty" sub-form, that update is automatic and is caused by the sub-form being linked to the main form.
 
If the users don't click on the button, maybe you can then "click it" for them. For example, when the form or the app closes (or opens), you can run a procedure to check if there were any emails that needed to be sent and then send them at that time. Just a thought...
right, I think that's a good idea
 
I'm not sure how you are triggering the AfterUpdate event on the main form Before the subform record gets saved. You need to put in some message boxes in both the sub and main form's Before and After Update events and walk slowly through the process. Here is a link to a database and some videos on how form/control events work, expecially concentrating on the BeforeUpdate event. But, trying to use this sample will require watching at least one of the videos so you understand how the sample works. Then you have to import your forms so you can test them inside my training app. So, try the message boxes first, it is less work.

When focus moves from the subform to the main form, the subform record ALWAYS gets saved before control shifts to the main form and it makes no sense for the main form's AfterUpdate event to run if its BeforeUpdate event didn't run first. PS - your validation goes in the BeforeUpdate event since it is the last event that runs BEFORE the record gets saved and the AfterUpdate event doesn't run until AFTER the record is saved. So, if your validation code is in the Form's AfterUpdate event, you are closing the barn door after the horses have escaped. That bad data has already been saved. This was the impetus for making the example in the first place - people are not using the two events correctly.
 

Users who are viewing this thread

Back
Top Bottom