Which Event to Use?

Q

Question Boy

Could someone enlighten me as to which even to use on a form to know when the
user enter information and actually creates a new record.

I was looking at the Dirty, but will this not continually fire for every
change made, keyboard stroke....?! I only need to trigger this event once at
the creation of a new record and never again.

Thank you,

QB
 
J

Jim Burke in Novi

Before Insert is triggered before you insert a new record, so if you can do
whatever you need to do right before the record is written you can do it
there. I'm pretty sure the On Current event will get triggered as soon as the
new record is opened, so if you need to do something right then you should be
able to put the code in the On Current event proc and check the value of
Me.NewRecord:

Private Sub Form_Current()

If Me.NewRecord Then
' perform actions for a new record here...
 
B

bcap

Depends what you mean by "creates a new record".

The Dirty event fires when a user begins entering data for a new record (or
begins amending an existing record). It only fires once, when the form is
first "dirtied". It will not fire again while the form remains dirty.

However, no record is created in the database at this point, not until
record is saved (at which point the form is no longer dirty).

When the record is saved:

The BeforeUpdate event fires immediately before the save (it is not
guaranteed at this point that the save will be successful). And the
AfterUpdate event fires after the record has been successfully saved (but
not if the save was unsuccessful).
 
A

Albert D. Kallal

The event that fires when the user starts typing and creates a record is
called;


Before Insert


The above event is a thus a good place to put code that sets up some fields
that you can't setup a default for.

You "could" use other events, but then that code tends to dirty the record
before the user may want to add that record.

the above also means if you open a form in add mode, and the user does NOT
type anything but closes the form, then you not have a blank record, or a
record that been half filled out and dirtied by some of your code running to
setup some controls...

So, the above is the event you are looking for....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top