Msgbox problem

L

Leslie Isaacs

Hello All

This works:

Private Sub Command55_Click()
On Error GoTo Err_Command55_Click
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit_Command55_Click:
Exit Sub
Err_Command55_Click:
MsgBox Err.description
Resume Exit_Command55_Click
End Sub

.... but this doesn't - when I try it, if I click "No" the record is not
deleted (as expected) but when I click "Yes" I just get a 'ping' and the
record is not deleted. Is this a bug?

Private Sub Command53_Click()
On Error GoTo Err_Command53_Click
If MsgBox("Are you sure you want to delete this session?", vbQuestion +
vbYesNo, "") = vbYes Then
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If
Exit_Command53_Click:
Exit Sub
Err_Command53_Click:
MsgBox Err.description
Resume Exit_Command53_Click
End Sub

Hope someone can help
Many thanks
Leslie Isaacs
 
A

Arvin Meyer [MVP]

Try this instead:

If MsgBox("Are you sure you want to delete this session?", vbQuestion +
vbYesNo, "") = vbYes Then

DoCmd.RunCommand acCmdDeleteRecord

Else
'Do nothing
End Sub

If it still won't delete it, try selecting the record and manually deleting
it. You may have a problem with referential integrity not allowing a delete,
or perhaps a permission issue, not allowing the delete.
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 
L

Leslie Isaacs

Arvin

Thanks for your speedy reply.
I know it's not a referential integrity or permission issue because the code
without the nsgbox works fine - and so does Ctlr-minus. I tried your code
and this came up with "The command or action 'Delete Record' isn't available
now".
I'm confused: hope you can help!

Many thanks
Les
 
A

Arvin Meyer [MVP]

Try selecting the record first (although it shouldn't be necessary):

If MsgBox("Are you sure you want to delete this session?", vbQuestion +
vbYesNo, "") = vbYes Then

DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdDeleteRecord

End If
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads
http://www.datastrat.com
http://www.mvps.org/access
 

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