Date Function

A

akpud

How do I set the default value of a date to be updated each time the record
is changed? This field will tell me the last time I accessed and updated the
record.
 
A

Alex White MCDBA MCSE

try in the 'on before update' event for the form

me.myDate.Value = now

or put the above line behind your button on the form that either saves the
record or closes the form.
 
O

Ofer

What Alex wrote is right, but the problem with it that if you get into a
field and enter the same value it will update the date field when infact you
didnt change it, now I dont knew if that what you had in mind.
if not then on the on current event of the form you can save the records in
variables and on the before update event on your form you can check if the
values changed and only then change the date field.
 
A

akpud

Thanks for your replies guys - but as a new user of Access this is all too
complicated. The simplest solution for me would be to type the date into the
record. I have the Field Date Type set to "Date/Time". Is there an easy way
to set the Default Value to put in the current date whenever a record is
updated? If not, no sweat, I'll simply insert it manually - and thanks for
your assistance.
 
O

Ofer

You can put a default value on a field but the date will be updated only when
you add a new record but not when you update a record.
To change the date when update there some code involved.
Its not hard to walk you through.
 
A

Alex White MCDBA MCSE

Hi,

on the form that is bound to the recordset,

get into code view and in the 'before update' event for the form type the
following.

me.txtDate.value = now

this is assuming that you have a control called txtDate and it is a textbox
bound to the date field for the recordset.
 
A

akpud

Thanks Ofer - much appreciated. If you have the time I'd certainly be
willing to give it a go. Just please be specific about where the code is to
go. Thanks!
 
O

Ofer

Just as Alex wrote to you it the basic and a simple thing to do.
either get to the code as Alex Suggested, or click on the top left side of
the form you'll get the properties of the form. One of then called before
uodate, select the code builder and then insert the code Alex Suggested.
If you want to get into more complicated code and be more accurate then tell
me.
 
A

akpud

Here's what I see in the Code Builder - Form - BeforeUpdate:

Private Sub Form_BeforeUpdate(Cancel As Integer)

End Sub

Where do I put your code? Do I erase the lines above?
 
O

Ofer

In the middle,

Private Sub Form_BeforeUpdate(Cancel As Integer)
me.myDate.Value = now
End Sub

akpud said:
Here's what I see in the Code Builder - Form - BeforeUpdate:

Private Sub Form_BeforeUpdate(Cancel As Integer)

End Sub

Where do I put your code? Do I erase the lines above?
 
A

akpud

Hi Ofer - just wanted to thank you for your help. Can't get it to work so
I'm just doing it manually for now.
 
Top