From: Bob H on
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
From: BruceM via AccessMonster.com on
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.

Bob H wrote:
>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

--
Message posted via http://www.accessmonster.com