Odd Error Message

M

Mike Revis

I have the following code on my form to delete the current record.

Private Sub cmdDelete_Click()
On Error GoTo Err_cmdDelete_Click

DoCmd.RunCommand acCmdDeleteRecord

Exit_cmdDelete_Click:
Exit Sub

Err_cmdDelete_Click:

'Suppress No Current Record message
If Err.Number = 3021 Then
Resume Exit_cmdDelete_Click
Else
MsgBox Err.Description
End If

End Sub

When I click the button I get the standard Access message about "are you
sure you want to delete?".

If I click yes everything proceeds as expected.

If I click no I get an error message as follows.

Microsoft Access can't find the field '|' referred to in your expression.

If I comment out the
'Else
'MsgBox Err.Description

I do not get the error message. I'm pretty sure that's because I commented
it out.

As always any thoughts, comments or suggestions are welcome.

Best regards

Mike
 
J

Jeff Boyce

Mike

Another approach, rather than taking the error hit and Resume-ing on past
it, would be to use the

DoCmd.SetWarning False

method to "hide" the warning about deleting. Of course, should you fail to
remember to

DoCmd.SetWarning True

afterwards, you will NEVER know when Access is choking on a chicken bone...

--
Regards

Jeff Boyce
Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/
 

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