Which Form event?

GaleT

Registered User.
Local time
Today, 14:56
Joined
Oct 18, 2019
Messages
72
I am using a single form to add, edit and view records. When I add a new record I would like to populate the "CreatedOn" form field with the current date. I think I can use a Form event for this but I can't figure out which one. Or is there a better way of doing this?

Gale
 
I would use afterupate
 
I would use a Default Value... :)
 
Thank you MajP and the DBguy... I was hoping there was an event that knew when a New document was being created. I think if I used the AfterUpdate event I would have to determine if a new document had been created verses an update on an existing document and that's pretty complicated to me. But for this requirement the Default Value should suffice... I should have thought of that myself... but I didn't. :-)

Thanks again to both of you.

Gale
 
Thank you MajP and the DBguy... I was hoping there was an event that knew when a New document was being created. I think if I used the AfterUpdate event I would have to determine if a new document had been created verses an update on an existing document and that's pretty complicated to me. But for this requirement the Default Value should suffice... I should have thought of that myself... but I didn't. :)

Thanks again to both of you.

Gale
Hi Gale. MajP and I were happy to assist. Good luck with your project.
 
I was hoping there was an event that knew when a New document was being created.

For other needs the Insert events might be appropriate, and you can always test in any event:

If Me.NewRecord Then
 
Thank you pbaldy, I'll look into the insert events for future needs... "If Me.NewRecord Then " that little addition to your post really makes it useful to me... just what I needed :-)
 
Thank you Pat, I understand what you are saying and I appreciate the comment. I can see I will need to do more reading before using form events, they are a little confusing. In regard to your use of the Default value in the table, I realized that earlier today but I am so inexperienced with Access that I decided to keep my tables as simple as possible with no auto-populated columns. So all calculation takes place in the one and only form. I will copy your comment into my "Access Forms" note file for future reference.

Gale
 
This puts the form into an endless loop
To be clear that is not correct, and that is simple to prove.
Code:
Private Sub ProposalNumber_AfterUpdate()
  Me.ProposalNumber = 5
End Sub

Private Sub ProposalNumber_BeforeUpdate(Cancel As Integer)
  MsgBox "Before"
End Sub
Further changing values in any control by code does not fire any update event. That is also easy to prove

I do agree that afterupdate was not a good choice, for this scenario. However, there is no harm in setting values in the after update.
 
Pat is fully capable of defending herself but I'll point out that the original question related (it appears anyway) to form level events, not control level events (bold added):

I think I can use a Form event for this

and I suspect Pat assumed you were suggesting the form's after update event. It's certainly possible that the term "Form" was being used more generically. Code in the form's after update event changing the value of a bound field will indeed cause an endless loop, or perhaps more accurately re-dirties the form and leaves it on the record it was on. I just tested and couldn't leave a record via the navigation buttons after changing a value.
 
Yes you are correct the OP and Pat were referring to form events, and I was thinking control events. I stand corrected.
the original question related (it appears anyway) to form level events, not control level events
 
Keep in mind that if a record is edited, it will again update to Now, so it's going to act more like a "last modified".
 
Keep in mind that if a record is edited, it will again update
Not if using default value property. It is viewable for an un-saved new record but it doesn't actually exist until the record is saved. If an existing record is edited, default value doesn't come into play.
 
Not if using default value property. It is viewable for an un-saved new record but it doesn't actually exist until the record is saved. If an existing record is edited, default value doesn't come into play.
I do both. A default date for the date created (modifiable by user if desired), and a last modified field that is set before update. The latter is not editable by the user.
 

Users who are viewing this thread

Back
Top Bottom