Challenge with delete button

3699wat

Registered User.
Local time
Today, 15:43
Joined
Oct 28, 2002
Messages
83
I have a delete button on a form 9developed with the wizard) to delete a record. I have put in a message with the code showing like this

Private Sub Command74_Click()
On Error GoTo Err_Command74_Click

If MsgBox("Delete record?", vbYesNo, "Delete") = vbNo Then
Else

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

End If
Exit_Command74_Click:
Exit Sub

Err_Command74_Click:
MsgBox Err.Description
Resume Exit_Command74_Click

End Sub

1. The standard Access message are still showing up
2. The record only shows as deleted after closing / opening the form
 
You can eliminate the delete message by going into 'Options and unclicking the 'Confirm Deletes'.

To solve #2 you need to put a Me.Requery after all the commands.
 
Under the Edit / Find tab I only see a section with
Confirm
record changes
document deletions
action queries

not confirm deletes
Do I use one of those????
 
You need to turn the error messages off and then back on again

Private Sub Command74_Click()
On Error GoTo Err_Command74_Click

DoCmd.SetWarnings False

If MsgBox("Delete record?", vbYesNo, "Delete") = vbNo Then
Else

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

End If
Exit_Command74_Click:
Exit Sub

Err_Command74_Click:
MsgBox Err.Description
Resume Exit_Command74_Click

DoCmd.SetWarnings True
End Sub


HTH
Dave
 
Do MenuItem is now obsolete in access according to Microsoft, however they've forgotten to tell the Wizards, you should replace MenuItems with their RunCommand equivalents.
 
Oldsoftboss has the correct approach ... but the "Warnings" are being turned On and Off at the wrong place in the code he posted. And you don't need the "Else" in the code the way it is written below.

Private Sub Command74_Click()
On Error GoTo Err_Command74_Click

If MsgBox("Delete record?", vbYesNo, "Delete") = vbYes Then
DoCmd.SetWarnings False
DoCmd.RunCommand acCmdDeleteRecord
DoCmd.SetWarnings True
End If

Exit_Command74_Click:
Exit Sub

Err_Command74_Click:
MsgBox Err.Description
DoCmd.SetWarnings True
Resume Exit_Command74_Click

End Sub

RDH
 
Sorry Rick - I should avoid too many late nights.
PS Dont forget to add the requery

Dave
 
Well ... you are right Oldsoftboss .... a "Requery" should be thrown in there .......

...... maybe beween the two of us, we'll get something that works .... LOL

RDH
 

Users who are viewing this thread

Back
Top Bottom