Subform Enter event does not fire as expected (1 Viewer)

Rx_

Nothing In Moderation
Local time
Today, 13:13
Joined
Oct 22, 2009
Messages
2,803
Private Sub sfROWLegalInfo_Enter() ' name of the sub form
blAddNewMode = False
End Sub

A form with several subforms. A combobox selection determines what subforms can have data entered. Once data is entered in the subform the combobox is locked down by setting a boolean value to false.

So, once the main form choices are made, clicking into a subform will change the boolean blAddNewMode.

What was expected:
Clicking from a control on the parent Form down to a control in the subform (i.e. enter the subform) would trigger this event. But it does not. :confused:

What is the best way to notify the parent form variable that the focus has gone into a sub-form?
 

HiTechCoach

Well-known member
Local time
Today, 14:13
Joined
Mar 6, 2006
Messages
4,357
Private Sub sfROWLegalInfo_Enter() ' name of the sub form
blAddNewMode = False
End Sub

A form with several subforms. A combobox selection determines what subforms can have data entered. Once data is entered in the subform the combobox is locked down by setting a boolean value to false.

So, once the main form choices are made, clicking into a subform will change the boolean blAddNewMode.

What was expected:
Clicking from a control on the parent Form down to a control in the subform (i.e. enter the subform) would trigger this event. But it does not. :confused:

What is the best way to notify the parent form variable that the focus has gone into a sub-form?

Based on you description of what is happening I woudl use the Parent form's After Update event link this:


Code:
Private Sub Form_AfterUpdate()

   blAddNewMode = False

End Sub


Why? When you navigate from the parent for to a sub form, the parent form will automatically force a save of any changes. Since I assume this will only happen for a new record, then the record will need to be save.



Note: You can test to see if a form is editing a new record like this:


Code:
If Me.NewRecord = True

  ' handle a new rcord
Else

  ' handle an existing record.
End If

I use this in a Form's On Current event for "locking" a form.
 

Rx_

Nothing In Moderation
Local time
Today, 13:13
Joined
Oct 22, 2009
Messages
2,803
:) Of course!!!
The AfterUpdate event does fire! That is perfect for this situation.
I will use the parent form to fire it and update a form global variable.

I was using the code below in a function to test if a subform had any records or not. But, when adding a new record to the parent, the subforms still report the previous record counts (because as you pointed out, we have yet to save the new record at the parent, which then would force the sub forms to point to a new record set for new record entry)

If Me.sfROWLeaseInfo.Form.RecordsetClone.RecordCount > 0 Then
blIsLeaseNotificationPopulated = True ' Different sub form shown here
Else

Once a persons sets up the combo boxes (which uses business rules to determine what sub forms are activated) I can lock down the choices using a boolean because the data is written to the recordset and the focus is now on a linked table (i.e. subform)

Access 2008
 
Last edited:

dkinley

Access Hack by Choice
Local time
Today, 14:13
Joined
Jul 29, 2008
Messages
2,016
AFAIK, the Got Focus event does not fire for a form in a sub form control.

EDIT: Just tested it in 2003 and is does not work.

I hmmm'd it then tested it, too - in 2007.

You are correct, it doesn't work unless you click on the record selector in the subform - which isn't what one would want normally. That is, only in datasheet view.

The OnEnter event did fire (of the subform frame, not in the form itself). It would fire even if one tabbed into it. However, you would then have to test for conditions to see if one wanted to do something. The AfterUpdate event of the parent form is a much smarter route since there is no references required for the condition.

Anyhow - just FYI. Thanks for the correction.

-dK
 

liamfitz

Registered User.
Local time
Today, 20:13
Joined
May 17, 2012
Messages
240
Could I use this 'AfterUpdate' event to add/update records in my sub-form. Maybe I should explain...

I have a subform, which shows related Client information. In this case, they are referral details ( i.e. Referral_ID, Referral_Date, Assessment_Date etc. ) of referrals relating to the current client being displayed in the main form. I would like to ( or need to ) on entering a referral date ( new referral ), extract DatePart information from thsi field,a nd along with Client info. on the Main Form, create a concatenated string to enter into the Referral_ID (P.K.) field of this newly created record. Any suggestions ?
:confused::confused:
 

HiTechCoach

Well-known member
Local time
Today, 14:13
Joined
Mar 6, 2006
Messages
4,357
I would like to ( or need to ) on entering a referral date ( new referral ), extract DatePart information from thsi field,a nd along with Client info. on the Main Form, create a concatenated string to enter into the Referral_ID (P.K.) field of this newly created record.

I believe the reason what you want to do is so confusing is because it is not normally done or consider to be Best Practice. When you violate the basic rules of data normalization it causes things to become very difficult and error prone.

I would recommend using an auto number data type for the Primary Key (P.K.). What you are describing as the Referral_ID can be calculated as needed and should not be stored.
 

liamfitz

Registered User.
Local time
Today, 20:13
Joined
May 17, 2012
Messages
240
Thank You. Do you mean by 'calculated', created at run-time in a variable ( and displayed ), but not actually written to the database, for a permanent record ?
 

HiTechCoach

Well-known member
Local time
Today, 14:13
Joined
Mar 6, 2006
Messages
4,357
Thank You. Do you mean by 'calculated', created at run-time in a variable ( and displayed ), but not actually written to the database, for a permanent record ?

Basically, yes. You can do the calculation in a control's control source. You can use a Calculated Field in a query, and also a VBA variable. I ude a calculated field in a query a lot. The way to appears like other field int eh tables in reports and forms.

The rule to follow is avoid storing data in a record that is is calculated for other field in the same record. This helps insure that your calculated data is correct.
 

Users who are viewing this thread

Top Bottom