Update "EditDate" field to now in form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I have an "EditDate" field on a form that I want to automatically update to today's date either when the form is opened, closed, or when the user moves to another record. I'm pretty sure I need code in the OnOpen or BeforeUpdate form property but I can't seem to get it right. Can anyone help me
Nancy
 
Me!NameOfTextBox = Date()

If you want it updated when the form is opened and/or when the user moves to
a new record, you'll need to place the code in Current event. This event is
fired whenever the form moves to a record, including when the form is opened
and moves to the first record, so if you have it in the Current event
there's probably no need to have it in the Open or Load events as well.

Updating it when the form is closed is, I think, problematic. If it's a
bound control (you're storing this date in a field in the table the form is
bound to) I think that's going to be a problem, because changes are saved
*before* the form's Unload or Close events are fired. If it's an unbound
control, there wouldn't be any point in setting it in the Unload or Close
events, as no one would see it until they opened the form again, when it
would be reset anyway.

If you just want it updated when the record is saved, then the BeforeUpdate
event of the form would be the event to use.

--
Brendan Reynolds (MVP)

NNester said:
Hi,
I have an "EditDate" field on a form that I want to automatically update
to today's date either when the form is opened, closed, or when the user
moves to another record. I'm pretty sure I need code in the OnOpen or
BeforeUpdate form property but I can't seem to get it right. Can anyone
help me?
 
Thanks, Brendan. The EditDate field is bound to my tblAccounts. Just to clarify, I need to make sure the record is updated to show when a sales rep makes changes to the record. I also need to make sure that this code only affects records that are actually modified, not just looked at with no changes to any fields. Thus, I'm not sure on what control or property the code needs to be added

Also, is there any difference between using =Date() vs. =Now()

I really appreciate your time
Nanc
 
You should put te code in the beforeupdate event
as for the difference between Now() and Date()? simply now() contains the
time as well..

HTH

Pieter
NNester said:
Thanks, Brendan. The EditDate field is bound to my tblAccounts. Just to
clarify, I need to make sure the record is updated to show when a sales rep
makes changes to the record. I also need to make sure that this code only
affects records that are actually modified, not just looked at with no
changes to any fields. Thus, I'm not sure on what control or property the
code needs to be added.
 
Allen Browne has an article on 'Building an Audit Log' that you may find
useful, at the following URL ...

http://members.iinet.net.au/~allenbrowne/AppAudit.html

--
Brendan Reynolds (MVP)

NNester said:
Thanks, Brendan. The EditDate field is bound to my tblAccounts. Just to
clarify, I need to make sure the record is updated to show when a sales rep
makes changes to the record. I also need to make sure that this code only
affects records that are actually modified, not just looked at with no
changes to any fields. Thus, I'm not sure on what control or property the
code needs to be added.
 
Back
Top