View Full Version : AfterUpdate crashes; BeforeUpdate works


danly
11-08-2000, 11:23 AM
I put a simple command in the AfterUpdate event property of a form, to update a "modified date" field:

Private Sub Form_AfterUpdate(Cancel As Integer)
Me![txtModDate] = Date
End Sub

Then when I try to add or edit a record and go to the next one, I get the message

"You can't go to the specified record--you may be at the end of a recordset."

And I can't save the record at all.

When I take that same code and put it in the BeforeUpdate event property of the form, it works fine.

What's so different about those two that they behave so differently?

Thanks in advance to anyone who has insight into this problem.

Dan Lee

Richie
11-08-2000, 01:52 PM
Is it not because the record has already been saved after form update? Try moving it to the after update of a control.

danly
11-09-2000, 04:49 AM
Thanks for the tip. I put the event on the whole form rather than a control because I want the mod date to update on any data change, not just one or two fields.

And it's not that the record is already saved. When I try to exit the form, I am told that the edit or addition can not be saved at all.

Dan

Keith P
11-09-2000, 05:45 PM
The beforeUpdate is the place to put your code. As your code itself creates an update you are creating a never ending loop, e.g. afterUpdate update, afterupdate update etc.

Keith P
11-09-2000, 05:45 PM
The beforeUpdate is the place to put your code. As your code itself creates an update you are creating a never ending loop, e.g. afterUpdate update, afterupdate update etc.

danly
11-10-2000, 06:24 AM
Keith,

That totally makes sense. Thanks for that bit of wisdom.

From Florida, the current center of the political universe,

Dan