MainForm to Subform Focus (1 Viewer)

damian

Registered User.
Local time
Today, 13:11
Joined
Jun 27, 2004
Messages
87
Hi
Is it possible to prevent the AfterUpdate event firing on a main form when a subform on the same form has been selected?

Have tried Screen.ActiveControl.Name to identify if the subform has received the focus but it appears that the main form AfterUpdate event fires and the last control to have the focus is the one on the main form immediately prior to shifting focus onto the subform.

The code in the AfterUpdate event is to send an automatic e-mail of the record in the main form that has either been added or has been edited – tried and trusted method but the presence of a subform throws a spanner in the works.

Thanks
 

mdlueck

Sr. Application Developer
Local time
Today, 08:11
Joined
Jun 23, 2011
Messages
2,631

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 13:11
Joined
Sep 12, 2006
Messages
15,652
one way may be this

in the currentevent, lock the subform if you are on a newrecord (you don't to be selecting the subform with no main form record)

in the dirty event lock the subform

in the forms afterupdate event unlock the subform

-----
this way, the subform is only usable if the main form record has not been dirtied.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 08:11
Joined
Feb 19, 2002
Messages
43,263
The AfterUpdate event only fires if something got updated. Is the user changing the record or is your code changing the record? If the user changed it, the email should be sent. If your code changed it, stop it! Your code should not be changing a record that the user hasn't first dirtied.

If you don't want to send the email until the user has finished with the subform, that's a different problem. There is no way to identify when a user has finished adding rows. He has to tell you. That means that you will need to add a button to the main form the user can press when his update is complete.
 

damian

Registered User.
Local time
Today, 13:11
Joined
Jun 27, 2004
Messages
87
Thanks for the responses.

Essentially what I need is to somehow intercept and stop the AfterUpdate event of the mainform by identifying if the subform has been clicked. Focus could therefore go back and forth between main form and subform without trigeering the automatic e-mail.
 

damian

Registered User.
Local time
Today, 13:11
Joined
Jun 27, 2004
Messages
87
Apologies Pat - little engrossed in the Ireland v Italy soccer match and didn't see your response.

It is the user that is changing the record not code. However as they can click on the subform, this will trigger the main form afterupdate event at some stage even if I disabled the subform up until all fields in the main form were completed.

Reason why I need to use the afterupdate event is to capture any subsequent editing of the record so that it's also pinged off in an e-mail
 

mdlueck

Sr. Application Developer
Local time
Today, 08:11
Joined
Jun 23, 2011
Messages
2,631
Apologies Pat - little engrossed in the Ireland v Italy soccer match and didn't see your response.

Aaahhh, valid excuse! I have fond memories of watching France vs Italy.

It is the user that is changing the record not code. However as they can click on the subform, this will trigger the main form afterupdate event at some stage even if I disabled the subform up until all fields in the main form were completed.

Reason why I need to use the afterupdate event is to capture any subsequent editing of the record so that it's also pinged off in an e-mail

This sort of fine UI control is frightfully complicated with Access and Subforms.

To get it to work consistently it is necessary to wire code to each/many controls AfterUpdate event and run a state check of all controls of interest. Access does not have bubbling events so there is no way to capture events at a higher level than the individual control and thus centrally process the event.

Could you perhaps process the form controls in a button event and mandate that users would need to push one button in order to process the form / subforms? That is what I ended up doing with my two monster forms each with multiple subforms on them.
 

damian

Registered User.
Local time
Today, 13:11
Joined
Jun 27, 2004
Messages
87
Looks like I'll have to accept defeat on both this one and the football..... Thanks Michael
 

Users who are viewing this thread

Top Bottom