Automatically update to today's date (1 Viewer)

mariaw

Registered User.
Local time
Today, 14:27
Joined
Jun 9, 2006
Messages
88
Hi

I have a table which has a date field in it, where the default value is Now().

How do I get this field to automatically update in the table to "today's date"?

Thanks

Maria
 

ColinEssex

Old registered user
Local time
Today, 14:27
Joined
Feb 22, 2002
Messages
9,117
Firstly, you should be entering data via a form and not direct into the table.

Then you can use the Now() or Date() function on the form.
Col
 

grnzbra

Registered User.
Local time
Today, 14:27
Joined
Dec 5, 2001
Messages
376
Unless you need to know the time of the entry, be sure to use the Date() function. Otherwise, using Between Date1 and Date2 will end up not picking up Date2.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 09:27
Joined
Feb 19, 2002
Messages
43,223
How do I get this field to automatically update in the table to "today's date"?
In what context? After you change a record on a form? After you update a record with a query?
 

mariaw

Registered User.
Local time
Today, 14:27
Joined
Jun 9, 2006
Messages
88
Hi Pat

Once the record has been saved into the table (by filling in the form) - I want the table to update one field to today's date each time it is opened

Maria
 

grnzbra

Registered User.
Local time
Today, 14:27
Joined
Dec 5, 2001
Messages
376
I think you would use the OnCurrent event for the form to set the field to Now(). Every time someone goes into the record, the date/time will be reset. Or are you talking about looking at it directly in the table.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 09:27
Joined
Feb 19, 2002
Messages
43,223
You really want to update a record because someone scrolled through it? Updating a change date if something is changed is very common. You would do that in the form's BeforeUpdate event. To update a record that someone just passes through, you would use the Current event as suggested by grnzbra.

Me.DateField = Now() 'stores both current date and current time
or
Me.DateField = Date() 'stores only current date
 

Abbosy

Registered User.
Local time
Today, 06:27
Joined
Dec 4, 2013
Messages
59
I have tried the code suggested by Pat Hartman in BeforeUpdate event but it didn't work.
Then I changed it to OnCurrent and it didn't have the effect I wanted it to happen.
I have a date field set to =Date(), which works fine when I go to it first time, i.e. a fresh record. When I go into it again (like when I sell extended warranty) it doesn't update the date to today's.
I really need to do this guys and I'm sure there is a way.
Thanks in advance for your help.
 

pr2-eugin

Super Moderator
Local time
Today, 14:27
Joined
Nov 30, 2011
Messages
8,494
What you have done (based on the information you have provided) is set the Default value. You need to write the code inside the Form's Before update..
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me.yourDateField = Date()
End Sub
 

Trilback

Registered User.
Local time
Today, 09:27
Joined
Nov 29, 2013
Messages
88
Hi

I have a table which has a date field in it, where the default value is Now().

How do I get this field to automatically update in the table to "today's date"?

Thanks

Maria

For me I have a field in my table called cdate and set the default value to = now() and just change the format of the date and time. Evertime I create a record using my form is adding the current date or time which ever I choose. Simple and easy.
 

chapterhouse

New member
Local time
Today, 06:27
Joined
Jan 30, 2015
Messages
8
Hi,
Regarding:

Code:
Private Sub Form_BeforeUpdate(Cancel As Integer) Me.yourDateField = Date() End Sub

I was wondering if this works in Access 2007.

Can't seems to get it to work.
 

mhrjnlyn

New member
Local time
Today, 19:12
Joined
Jul 23, 2020
Messages
1
What you have done (based on the information you have provided) is set the Default value. You need to write the code inside the Form's Before update..
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
    Me.yourDateField = Date()
End Sub
i have tried that but it didn't work on my access 2010.
is there any other way?
thanks for your help in advance.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 08:27
Joined
Feb 28, 2001
Messages
27,142
OK, this is a very old thread. However, so far as I know, the Form_BeforeUpdate event is still legal and the code posted by our friend pr-eugin should still work even for Ac2019, but CERTAINLY for 2010. (I have 2010 myself.)

What is the result that you get that you believe to be incorrect? What did you do, what did you expect, what did you see?
 

Users who are viewing this thread

Top Bottom