Run code on new record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

What's the best way to run code only when a new record is added to a bound
form?
I tried:

If IsNull(ClientID) THen
code here
End If

I placed this on an afterUpdate event for the first control likely to get
input thinking that the ClientID would be null initially. But the code does
not execute, making me think that my plan is no good.
Thanks, guys
 
The best way to run code on a new record depends on when you want to run the
code. Do you want to run the code as soon as you go to a new record or
before you try to save the new record?

In the first instance, you the form's Current event. Place the code inside
an If statement, such as

If Me.NewRecord Then
'run you're new record code here
End If

If you want to run the code before saving the record, you can use the form's
BeforeUpdate event. Again, you would use an If statement like the one above.

There is one more option, the BeforeInsert event. This will run as the user
tries to type the first character in the new record.
 
Back
Top