Update a field automatically when updating a record...

  • Thread starter Thread starter TheTruePhoenix
  • Start date Start date
T

TheTruePhoenix

Hi all,

I'm having trouble updating a field automatically when a record is
updated from a form... I have two fields, one is "updated by" which
will automatically get the user name, but only when the record is first
created, and the other is updated (date/time) which again will get the
original info when it was created (although this isn't needed as I have
a created date/time box which is autofilled anyway) but doesn't update
when you save changes to the document... Any ideas?

I might also post a link to the other issue I'm having (not related
although with-in the same database) which hasn't got a reply yet :(

http://groups.google.com.au/group/m...0753395a892/292f5fea88a0418a#292f5fea88a0418a
 
I'm having trouble updating a field automatically when a record is
updated from a form... I have two fields, one is "updated by" which
will automatically get the user name, but only when the record is first
created, and the other is updated (date/time) which again will get the
original info when it was created (although this isn't needed as I have
a created date/time box which is autofilled anyway) but doesn't update
when you save changes to the document... Any ideas?

Use the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as Integer)
<put any record validation code here>
Me![Updated By] = <whatever the user name is>
Me![Updated At] = Now
End Sub

John W. Vinson[MVP]
 
Worked a treat, thanks John ;) Not that it means much being a database
used by about 10 people and not making anyone any money but I gave you
credit in the code, hehe.

John said:
I'm having trouble updating a field automatically when a record is
updated from a form... I have two fields, one is "updated by" which
will automatically get the user name, but only when the record is first
created, and the other is updated (date/time) which again will get the
original info when it was created (although this isn't needed as I have
a created date/time box which is autofilled anyway) but doesn't update
when you save changes to the document... Any ideas?

Use the Form's BeforeUpdate event:

Private Sub Form_BeforeUpdate(Cancel as Integer)
<put any record validation code here>
Me![Updated By] = <whatever the user name is>
Me![Updated At] = Now
End Sub

John W. Vinson[MVP]
 
Not that it means much being a database
used by about 10 people and not making anyone any money but I gave you
credit in the code, hehe.

Well, that's more credit than I get lots of other places - so thank
you!

John W. Vinson[MVP]
 
Back
Top