Best Event for adding Fields to new Record (1 Viewer)

Djblois

Registered User.
Local time
Today, 15:02
Joined
Jan 26, 2009
Messages
592
I am using the AfterInsert event to add values to a new record as it is created.


Code:
Private Sub Form_AfterInsert()

    Me.tbSpecialOrderID = Me.Parent.tbSpecialOrderID
    Me.tbStatus = Me.Parent.tbStatus

End Sub

It works, adding the values correctly. However, it has a small side effect that I want to fix. In order to switch to another record, I need to click twice to unselect the new record. Is there a better event than AfterInsert that will add these values but not require the 2 clicks to get off the record?
 

theDBguy

I’m here to help
Local time
Today, 15:02
Joined
Oct 29, 2018
Messages
10,099
Hi. Maybe you could just set the default values for those two fields.
 

Djblois

Registered User.
Local time
Today, 15:02
Joined
Jan 26, 2009
Messages
592
There isn't a default value; they are based on the new parent record.
 

arnelgp

error reading drive A:
Local time
Tomorrow, 06:02
Joined
May 7, 2009
Messages
9,290
create a Link Master/Child Fields on your subform:

Link Master Fields: [tbSpecialOrderID], [tbStatus]
Link Child Fields: [tbSpecialOrderID], [tbStatus]

remove the code on the AfterInsert event of your subform.
 

Djblois

Registered User.
Local time
Today, 15:02
Joined
Jan 26, 2009
Messages
592
That would automatically add those fields then? But status may change, is that still the best method then?
 

arnelgp

error reading drive A:
Local time
Tomorrow, 06:02
Joined
May 7, 2009
Messages
9,290
if Status will change then use the subform's BeforeInsert, and not the AfterInsert event.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom