Delete not working in Access 2007

B

Bob H

I have been running a Acess 2007 database on a server for about 15
months, and now I want to delete certain records form it using the
cmdDelete button which has this code behind it:

Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

Select Case MsgBox("Are you ure you want to delete this record?", vbYesNo)
Case vbYes 'Do nothing: it saves by default.
Case vbNo 'Undo the changes, and close.


End Select
Exit_Save_Click:
Exit Sub

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

Exit_cmdDelete_Click:
Exit Sub

Err_cmdDelete_Click:
MsgBox Err.Description
Resume Exit_cmdDelete_Click

End Sub

I have found that the records are not deleted when I click the button,
so what am I missing here.

Thanks
 
B

BruceM via AccessMonster.com

For one thing, you are exiting the sub before deleting the record (at
Exit_Save_Click, which is not the current sub, but Access will run the Exit
Sub routine anyhow, I think. Also, the message box does nothing. The user
can click Yes or No, but you exit the sub in either case. Alternatively, if
you leave out the Exit Sub line at Exit_Save_Click, the record will be
deleted no matter what the user selects for Yes or No.
 

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

Top