Lubomir Burian
Lubomir Burian

Reputation: 11

How can I find in VBA (MS Access) if user "confirmed" or "cancelled" the delete of the record in the implicit Access message box?

the user in my database is allowed to delete records. There are several events associated with the Form I am using: Delete, BeforeDelConfirm and AfterDelConfirm

Between BEFOREDELCONFIRM and AFTERDELCONFIRM there is a dialog box that asks the user the following question: "You are about to delete 1 record(s). If you clock Yes, you won't be able to undo this Delete operation. Are you sure you want to delete these records?" Yes / No

How can I find in AfterDelConfirm event in VBA what he selected ?

why I need this - I want to insert a deleted record into an Audit_Table. The trouble is that I need to insert it only if the user confirmed the delete. Thanks in advance

-------------- This saves the deleted record regardless of the user's choice --------------

Dim Global_ModelKey As Integer      'used to store temporarily the ModelKey value 

Private Sub Form_Delete(Cancel As Integer)
Global_ModelKey = Me.modelKey.Value
End Sub

Private Sub Form_AfterDelConfirm(Status As Integer)
'--- SQL command ---
sql = '<sql command>
'--- display message with the SQL command to check syntax ---
result = MsgBox(sql, vbOK, "SQL check", "", 1000)

DoCmd.SetWarnings False
DoCmd.RunSQL (sql)
DoCmd.SetWarnings True

Global_ModelKey = 0
End Sub

Upvotes: 0

Views: 176

Answers (0)

Related Questions