Why can't I edit a record during a delete event?

C

Chaimribs

I'm trying to archive records instead of deleting them by adding a date into
a special field when the delete button is pushed.

This is the code I'm using.

Private Sub Form_Delete(Cancel As Integer)
If MsgBox("Do you want to delete this record?", vbOKCancel) = vbOK Then
Me.Field12 = Now()
End If
Cancel = True
End Sub

This should work except it just ignores the line "Me.Field12 =Now()." Also
there's no error.
What's wrong or is this a bug.

Thanx.
 
T

tina

you're on the right track, just using the wrong events. make sure your
form's RecordSource is filtering out records with a value in the "date
deleted" field (Field12), and try the following code, as

Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)

Cancel = True

End Sub

Private Sub Form_AfterDelConfirm(Status As Integer)

If MsgBox("Do you want to delete this record?", _
vbOKCancel + vbDefaultButton2) = vbOK Then
Me!Field12 = Now()
DoCmd.RunCommand acCmdSaveRecord
Me.Requery
End If

End Sub

note that i added an option in the msgbox to change the default focus to the
Cancel button, rather than the Ok button. i habitually set up my msgboxes to
default to the option that will *not* change anything - so the user has to
actively make a decision to alter the data by selecting the other button in
the msgbox. that's my insurance against twitchy little fingers hitting the
Enter key before the user's brain processes the message, and insurance
against those users who just automatically enter through msgboxes without
reading them at all.

hth
 

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

Similar Threads


Top