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

Djblois

Registered User.
Local time
Today, 00:17
Joined
Jan 26, 2009
Messages
598
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
Staff member
Local time
Today, 00:17
Joined
Oct 29, 2018
Messages
21,358
Hi. Maybe you could just set the default values for those two fields.
 

Djblois

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

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:17
Joined
May 7, 2009
Messages
19,169
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, 00:17
Joined
Jan 26, 2009
Messages
598
That would automatically add those fields then? But status may change, is that still the best method then?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 15:17
Joined
May 7, 2009
Messages
19,169
if Status will change then use the subform's BeforeInsert, and not the AfterInsert event.
 

Users who are viewing this thread

Top Bottom