Error 2501 Help

S

saj2004

I have a command button on my form that when clicked opens the insert
hyperlink dialog box. That works fine. The problem is when I click Cancel and
decide not to insert a hyperlink I get "Error 2501" I was wondering how I fix
my code to handle that error.

Here is my code for the button

Private Sub Command108_Click()
Me.[Attachments1].SetFocus
RunCommand acCmdInsertHyperlink

End Sub


Any help would be greatly appreciated. Thank you!
 
A

Allen Browne

Include error handling, and instruct it to ignore error 2501.

Example below:

Private Sub Command108_Click()
On Error Goto Err_Handler

Me.[Attachments1].SetFocus
RunCommand acCmdInsertHyperlink

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then
MsgBox "Error " & Err.Number & ": " & Err.Description
End If
Resume Exit_Handler
End Sub

If error handling is a new concept, see:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html
 

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