Automatically Update Date Field

  • Thread starter Thread starter Ron
  • Start date Start date
R

Ron

How do i build an event procedure to automatically update
with todays date, in a date field on a form? This is a
form I use to update records in my database and want not
to have to add the date I updated, but to let the program
do it for me. Database is called "Directory" and the date
field is called "Updated".
 
Use the form's BeforeUpdate event to write a value into the control that is
bound to the date field.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.DateFieldControlName.Value = Date()
End Sub

Simply put this code in the form's module and then select [Event Procedure]
from the dropdown list box next to the BeforeUpdate event for the form (in
design view) in the Properties window.
 
Didn't work, keeps removing () after the Date. I'm a
computer idiot. What is a control the is bound? How do I
make it bound?

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.DateFieldControlName.Value = Date
End Sub
-----Original Message-----
Use the form's BeforeUpdate event to write a value into the control that is
bound to the date field.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.DateFieldControlName.Value = Date()
End Sub

Simply put this code in the form's module and then select [Event Procedure]
from the dropdown list box next to the BeforeUpdate event for the form (in
design view) in the Properties window.

--
Ken Snell
<MS ACCESS MVP>

How do i build an event procedure to automatically update
with todays date, in a date field on a form? This is a
form I use to update records in my database and want not
to have to add the date I updated, but to let the program
do it for me. Database is called "Directory" and the date
field is called "Updated".


.
 
ACCESS will remove the () after Date when it "compiles" the code. No worry.

A control is bound to a field in the form's recordsource when the control's
Control Source property is set to the name of the field to which it is to be
bound. This is how you can write / view data to / from fields in the form's
recordsource.

If you don't display the value that is in the DateField, then you can just
include this field in the form's recordsource and then use the code that I
wrote to put the current date value into it.

Note that I'm using a generic name (DateField) for the name of the field
into which you want to store the date value. Replace that name with the real
name of your field.

--
Ken Snell
<MS ACCESS MVP>

Didn't work, keeps removing () after the Date. I'm a
computer idiot. What is a control the is bound? How do I
make it bound?

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.DateFieldControlName.Value = Date
End Sub
-----Original Message-----
Use the form's BeforeUpdate event to write a value into the control that is
bound to the date field.

Private Sub Form_BeforeUpdate(Cancel As Integer)
Me.DateFieldControlName.Value = Date()
End Sub

Simply put this code in the form's module and then select [Event Procedure]
from the dropdown list box next to the BeforeUpdate event for the form (in
design view) in the Properties window.

--
Ken Snell
<MS ACCESS MVP>

How do i build an event procedure to automatically update
with todays date, in a date field on a form? This is a
form I use to update records in my database and want not
to have to add the date I updated, but to let the program
do it for me. Database is called "Directory" and the date
field is called "Updated".


.
 
Back
Top