Auto fill date/time

sljensen

Registered User.
Local time
Today, 10:25
Joined
Jun 5, 2012
Messages
23
Hi, New user here.
When a new record in created via a form I need a field to auto enter the current Date/time.Can someone point me int he right direction?
 
When the form is being complete you could use the Event for After Update and in the code screen you can simply place in a command to add the date/time which is called Now()

Open your form in design view and select a field which gets completed, then select to show the properties and then use the Event Tab in the After Update click the elipse button on the right and select Code View then type in

me.YourDateFieldName=Now()

Save and close the VBA screen and when you complete that field and move away it will add the date and time.
 
Trevor,
I's struggling.
When the VBA screen opens there are several lines of text. I assume I insert the code between Private and End as shown. I changed YourDateFieldName to my field name of Date_Last_Modified. It looks like this:

Private Sub Date_Last_Modified_AfterUpdate()
Me.Date_Last_Modified = Now()
End Sub

It doesn't autopopulate when I move away from the record. Do I have to select the date? A pop-up calendar does show adjacent to the box.

Where did I go wrong?
 
That should work I have tested this several ways.

Do you have any restrictions on the form? is it possible to attach a copy of the database stripping out any sensitive data?
 
You can also use the GotFocus() method. As you want it to autofill.. AfterUpdate will be invoked after you move away from the record after making some changes.. Use the same code but inside GotFocus().. something like..

Private Sub Text21_GotFocus()
Me.Text21 = Date
End Sub
 
I'm not aware that the form has any restrictions.

Lets see if this works:
I stripped down the database to just a few tables most of the linked tables were removed. Don't know if that will cause issues.

Thanks for helping.
 

Attachments

I must be doing something wrong. I tried GotFocus() and didn't get the date cell to autopopulate either.
 
With a little more effort, this can be made much more complicated. :D

You can in the properties of the field in table design say Now(), so each new record is born with a time stamp.

On your form, you can put the same in the default property of the control bound to that field, and that will do the same.
 
Spikepl,
Can you expand on this:

You can in the properties of the field in table design say Now(), so each new record is born with a time stamp.


See how green I am?

Thanks
 
Sorry, but this is very basic stuff. Someone here might help you, but whil you wait I would suggest you google for an access tutorial on tables. It will take you 10 minutes and you are done. And don't forget to look in the help file (press F1) there might be some "How to" too. Finally you have the Access application itself. There is no death penalty on scouring around and trying things out.

My main point is that you need to do some basic work yourself, and learn how to do it. Both Help and Google are sufficient for that. Come back with questions for things that are not immediately available in either Help nor Google.
 
Spikepl,
Can you expand on this:

You can in the properties of the field in table design say Now(), so each new record is born with a time stamp.


See how green I am?

Thanks

Though I agree with the gentleperson above, I will say look towards the option of default values for a field :P
 
I would just like to point out, I agree with Pat...

Also I have noted that post#3 from sljensen had this

Code:
Private Sub Date_Last_Modified_AfterUpdate()
Me.Date_Last_Modified = Now()
End Sub

Code will only run when you update the field you want to update.
This afterupdate should be on another field, or on a button
 
I have; with the great advice from Pat, have learned the disadvantages and the horror of updating a Form After Update. It is more swift when you DO NOT update the Form after updating the record.

As mentioned by Kev, the code will not be updating; as you have to make some changes to the record already existing for the control source after update to work. sljensen I would suggest you to follow Pat's advice.
 
hello friends i have a form on which i want to add a field "Time" and i want that it will automatically fill with current time when i got focus on "Time" field. somehow i am unable to do it i need your help friends...


Thanks in advance.........
 

Users who are viewing this thread

Back
Top Bottom