Dialog box prevents record deleting

R

Rich Stone

I have a database with standard record function buttons. However, my 'Delete'
button seems to have a problem. When I add vb code to bring up a custom
dialgog asking the user whether they definitely wish to delete the current
record, nothing happens after it. However, when I remove the dialog box code,
the record deletes immediately the button is pressed.

My code is as follows:

x = MsgBox("Are you sure you wish to delete the current record?",
vbYesNo + vbExclamation)
If x = vbNo Then
Exit Sub
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If

Any ideas
 
J

John W. Vinson

I have a database with standard record function buttons. However, my 'Delete'
button seems to have a problem. When I add vb code to bring up a custom
dialgog asking the user whether they definitely wish to delete the current
record, nothing happens after it. However, when I remove the dialog box code,
the record deletes immediately the button is pressed.

My code is as follows:

x = MsgBox("Are you sure you wish to delete the current record?",
vbYesNo + vbExclamation)
If x = vbNo Then
Exit Sub
Else
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
End If

Any ideas

Can you verify that the user is indeed clicking the Yes button?

Do note that this code is seriously obsolete (the wizards are stuck back in
the last century). I'd suggest

Private Sub cmdDelete_Click()
Dim iAns As Integer
iAns = MsgBox("Are you sure you wish to delete the current record?", _
vbYesNo + vbExclamation)
If iAns = vbYes Then
DoCmd.RunCommand acCmdDeleteRecord
End If
End Sub

Try putting a breakpoint on your x= line (in the VBA editor click in the grey
bar on the left of the editing window) and step through the code to see if
something unexpected is happning; also be sure you don't have SetWarnings set
to False somewhere (it would suppress warning messages about failed deletes).
 
J

Jeff Boyce

Rich

Are you using an MS Access "dialog" box, or are you referring to the message
box (MsgBox(...))?

How are you confirming that the row is not deleted?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
R

Rich Stone

Thank you for your replies.

The button is on a form that shows each record at a time. I originally used
the wizard to create the delete button, hence the old coding. However, I did
change it to the revised method. I also have warnings off as I am using
custom dialog throughout the database.

The button works perfectly until I put the code in for the confirmation box
which doesn't make any sense as I've done this everywhere else in the
database with no problems at all.

I will first try turning the warnings back on. Then I will try to step
through the code and see what is happening. I have error catching in place
but there aren't any coming up!
 

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