Go Back   Access World Forums > Microsoft Access Discussion > Forms

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 09-11-2019, 05:03 AM   #1
Djblois
Newly Registered User
 
Join Date: Jan 2009
Posts: 590
Thanks: 0
Thanked 0 Times in 0 Posts
Djblois is on a distinguished road
Best Event for adding Fields to new Record

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?

Djblois is offline   Reply With Quote
Old 09-11-2019, 05:09 AM   #2
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 4,610
Thanks: 50
Thanked 1,053 Times in 1,034 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Best Event for adding Fields to new Record

Hi. Maybe you could just set the default values for those two fields.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Old 09-11-2019, 05:39 AM   #3
Djblois
Newly Registered User
 
Join Date: Jan 2009
Posts: 590
Thanks: 0
Thanked 0 Times in 0 Posts
Djblois is on a distinguished road
Re: Best Event for adding Fields to new Record

There isn't a default value; they are based on the new parent record.

Djblois is offline   Reply With Quote
Old 09-11-2019, 05:39 AM   #4
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,401
Thanks: 68
Thanked 2,703 Times in 2,588 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Best Event for adding Fields to new Record

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.
__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Old 09-11-2019, 06:36 AM   #5
Djblois
Newly Registered User
 
Join Date: Jan 2009
Posts: 590
Thanks: 0
Thanked 0 Times in 0 Posts
Djblois is on a distinguished road
Re: Best Event for adding Fields to new Record

That would automatically add those fields then? But status may change, is that still the best method then?
Djblois is offline   Reply With Quote
Old 09-11-2019, 06:51 AM   #6
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 4,610
Thanks: 50
Thanked 1,053 Times in 1,034 Posts
theDBguy has a spectacular aura about theDBguy has a spectacular aura about
Re: Best Event for adding Fields to new Record

Quote:
Originally Posted by Djblois View Post
There isn't a default value; they are based on the new parent record.
Hi. The default value would be the parent then.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Old 09-11-2019, 07:18 AM   #7
arnelgp
error reading drive A:
 
arnelgp's Avatar
 
Join Date: May 2009
Location: somewhere out there
Posts: 8,401
Thanks: 68
Thanked 2,703 Times in 2,588 Posts
arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice arnelgp is just really nice
Re: Best Event for adding Fields to new Record

if Status will change then use the subform's BeforeInsert, and not the AfterInsert event.


__________________
"Never stop learning, because life never stops teaching"
arnelgp is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Validating mandatory fields before adding record rmaciel Forms 3 12-09-2009 07:00 AM
Event for adding new record shevo General 2 03-13-2008 05:01 AM
Adding a new record with certain fields filled TomJamieson Modules & VBA 1 10-06-2006 05:30 AM
VBA adding a duplicate record without event John Nelson Modules & VBA 2 06-01-2005 07:36 AM
Adding fields in 2 records into new record Robert Saye Modules & VBA 0 06-12-2001 11:09 AM




All times are GMT -8. The time now is 04:52 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World