Adding and detecting new records

ClaraBarton

Registered User.
Local time
Today, 13:49
Joined
Oct 14, 2019
Messages
469
I'm calling a detail form from a list form. Usually the detail form is called with a where condition and goes to that record.
However, I also have a New button that calls the detail form in datamode:=acformadd.
To add a new record there are a couple routines I need to run first, so on load :
Code:
If me.newrecord then
     Call a routine
End If
The me.newrecord always returns 0 and skips to End.
How is this possible if I've called it acformadd? There is no data. It is new.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 04:49
Joined
May 7, 2009
Messages
19,248
you can also Check if your PK is Null for New record.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 13:49
Joined
Oct 29, 2018
Messages
21,479
I just tested that, and I got the expected results. Maybe you have other code that's saving the new record before the check, so it's not a new record anymore?
 

ClaraBarton

Registered User.
Local time
Today, 13:49
Joined
Oct 14, 2019
Messages
469
Well! Checking the PK works great! Why doesn't the other work? Thank you very much.
DBguy... since it's on the load event how would that be possible?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:49
Joined
Feb 28, 2001
Messages
27,196
Load events only fire once when the form is first loaded (and just after the Form Open event. Changing records (including creating a new record) uses the Current event, which might be where you need to do your testing. See this article to learn about the detailed order of events.

 

Gasman

Enthusiastic Amateur
Local time
Today, 21:49
Joined
Sep 21, 2011
Messages
14,327
If you walk your code you will see that the Current event is called after the Open and Load events. Plus a few others.
As Doc states, that would be where I would test.

What would happen, if I decided to add more than one record. Do I have to go back to the previous form and start all over again? :(
 

Users who are viewing this thread

Top Bottom