Date record last updated from Access 2002 form

G

Guest

I need to do what seems to be a simple thing.

I have a form based on a table. When the user updates any field, I want to
update a field on the underlying table with the date/time of the update. I
tried using the beforeupdate event, then using the recordset:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim rst As DAO.Recordset

Set rst = Me.Recordset

With rst
.Edit
!dtLastUpdate = Now
.Update
End With

MsgBox ("BeforeUpdate")

End Sub

I get error 3426 - action was cancelled by an associated object.

What am I doing wrong?

Thanks!
 
J

Jonathan Parminter

-----Original Message-----
I need to do what seems to be a simple thing.

I have a form based on a table. When the user updates any field, I want to
update a field on the underlying table with the date/time of the update. I
tried using the beforeupdate event, then using the recordset:

Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim rst As DAO.Recordset

Set rst = Me.Recordset

With rst
.Edit
!dtLastUpdate = Now
.Update
End With

MsgBox ("BeforeUpdate")

End Sub

I get error 3426 - action was cancelled by an associated object.

What am I doing wrong?

Thanks!
.
Hi Nick,

Probably record locking prevents editing an open record...

how about having the field as a textbox on the form with
visible set to false. Then use the before update event to
set the field to the current date and time?

Luck
Jonathan
 
B

Brendan Reynolds

If the dtLastUpdate field is included in the form's recordsource, you can
just refer to it as though it were a property of the form, there's no need
to go through the Recordset ...

Me!dtLastUpdate = Now()

My guess is that the problem you were experiencing probably has something to
do with trying to update the form's recordset in the form's before update
event procedure. The procedure runs just *before* the form's recordset is
updated, so if you think about it, you're effectively trying to update the
recordset before updating the recordset! :)

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top