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

  • Thread starter Thread starter Chaimribs
  • Start date Start date
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.
 
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
 
Back
Top