delete message confirmation issue

gilescis

D. Castaldo
Local time
Today, 15:43
Joined
Jan 23, 2006
Messages
106
I am trying to create a button to delete record, I have used the wizard and it works fine but now I want to have a confiirmation message to confirm that they really want to delete this record.

below is my code. The prompt works but the record never deletes.

Any Idea's


Private Sub cmdDeleteRec_Click()
On Error GoTo Err_cmdDeleteRec_Click

DoCmd.SetWarnings False
If MsgBox("Are you sure you want to delete this record?", vbYesNo, "Warning.........") = vbYes Then
Me!frm_Entry.SetFocus
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
Else
DoCmd.SetWarnings True
End If

Exit_cmdDeleteRec_Click:
Exit Sub

Err_cmdDeleteRec_Click:
MsgBoxErr.Description , vbExclamation, "Error #" & Err.Number
Resume Exit_cmdDeleteRec_Click

End Sub
:confused: :confused:
 
The way I do this is make the response from the message a variable and then do my IF statement. See below my changes.

Code:
Private Sub cmdDeleteRec_Click()
On Error GoTo Err_cmdDeleteRec_Click

Dim response as integer

DoCmd.SetWarnings False

response = MsgBox("Are you sure you want to delete this record?", vbYesNo, "Warning.........") 

If response = 6 then  '6 means yes
Me!frm_Entry.SetFocus
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
Else
DoCmd.SetWarnings True
End If

Exit_cmdDeleteRec_Click:
Exit Sub

Err_cmdDeleteRec_Click:
MsgBoxErr.Description , vbExclamation, "Error #" & Err.Number
Resume Exit_cmdDeleteRec_Click

End Sub
 
If MsgBox("Are you sure you want to delete this record?", vbYesNo, "Warning.........") = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End If


???
 
I tried both choices and neither works
Here is my updated code
Private Sub cmdDeleteRec_Click()
On Error GoTo Err_cmdDeleteRec_Click

If MsgBox("Are you sure you want to delete this record?", vbYesNo, "Warning.........") = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End If


Err_cmdDeleteRec_Click:
MsgBoxErr.Description , vbExclamation, "Error #" & Err.Number
Resume Exit_cmdDeleteRec_Click

End Sub
 
Code:
Private Sub cmdDeleteRec_Click()
On Error GoTo Err_cmdDeleteRec_Click

If MsgBox("Are you sure you want to delete this record?", 36, "Warning.........") = 6 Then
   DoCmd.SetWarnings False
   DoCmd.RunCommand acCmdDeleteRecord
   DoCmd.SetWarnings True
End If

Exit_cmdDeleteRec_Click:
   Exit Sub

Err_cmdDeleteRec_Click:
   MsgBoxErr.Description , vbExclamation, "Error #" & Err.Number
   Resume Exit_cmdDeleteRec_Click

End Sub


???
 
his makes no sense. If i use the following code. The recoed gets deleted. but if I use the second code it dont.
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70


Exit_cmdDelete_Click:
Exit Sub

Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click

End Sub
******************************************
Code 2
******************************************
Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

MsgBox("Are you sure you want to delete this record?", 36, "Warning.........") = 6

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70


Exit_cmdDelete_Click:
Exit Sub

Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click

End Sub
 
Whoops I ment This makes no sense

Sorry...........
 
I'm not sure why you are testing a pc of code that can't be used a building block to a more complex pc of code but,...

The code may act strange if you try to assign a value to a 'msgbox'

What about:

Code:
MsgBox "Are you sure you want to delete this record?", 36, "Warning........."  

DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
 
It is rare... but I have seen where the current record needs to be selected so that the code knows what to delete. See if this helps...

Code:
If MsgBox("Are you sure you want to delete the current record?", vbQuestion + vbYesNo, "Delete Record?") = vbYes Then
    DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdSelectRecord
        DoCmd.RunCommand acCmdDeleteRecord
    DoCmd.SetWarnings True
Else 'user clicked no
    MsgBox "Deletion was aborted.", vbInformation
End If
Also, You need to ditch using the outdated DoCmd.DoMenuItem commands. Just because the wizard creates that type of code does not make it the right thing to use.
 

Users who are viewing this thread

Back
Top Bottom