View Single Post
  #3  
Old September 18th, 2009, 09:46 PM posted to microsoft.public.access.tablesdbdesign
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Dialog box prevents record deleting

On Thu, 17 Sep 2009 04:57:02 -0700, Rich Stone
wrote:

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).
--

John W. Vinson [MVP]