Default Dates & Times in Existing Records

  • Thread starter Thread starter boconnor
  • Start date Start date
B

boconnor

For some reason this does not work. I believe that it is
because the records already exist, I am only updating
current records. Is there another way to default the date
and times?
-----Original Message-----
In the design view of the table you can create Default
values for each field.

Date() will give you the current date
Now() will give you the current date and time.

.
..
 
The default value of a table field only works on new
records. You need to implicitly update the date field of
you record each time you save changes to an existing
record and this can be done using the Dirty function. A
form that is bound to a data source will inititally have
an IsDirty value of False. When you make a change to the
record the IsDirty value changes to True. For each bound
control create an after update event to check the
form.Dirty value and if it returns True then update you
date control.

For example I have a form with the text box txt_test and a
text box txt_Date. I have an after update event on the
txt_Test text box which calls a function to check the
Dirty value of the form.


Private Sub txt_test_AfterUpdate()
Call CheckDirty
End Sub

Private Sub CheckDirty()
If Form.Dirty = True Then
txt_Date = Date
End If
End Sub

If the form.Dirty value is true the textbox txt_Date is
updated with todays date.

You will of course have to change the control names to
that on your form.

NOTE:
The Dirty property of a form only works on a bound form.
If you form is unbound this will not work.
 
Back
Top