Error 2501 Help

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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!
 
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
 
Back
Top