The RunCommand action was cancelled(Run-time error '2501')

D

Dave

When a user is inputing a hyperlink into a text box on my
form I have the Insert Hyperlink dialog box pop up
automatically with an On Click Event Procedure in my text
box with the following code...

Private Sub Resistance_Click()
RunCommand acCmdInsertHyperlink
End Sub

If you enter a hyperlink and press OK it works fine.
However if you click the Cancel button instead of entering
a hyperlink the debug error "The RunCommand action was
cancelled(Run-time error '2501')" appears. Is there a
work around to this???

Thanks David
 
D

Dirk Goldgar

Dave said:
When a user is inputing a hyperlink into a text box on my
form I have the Insert Hyperlink dialog box pop up
automatically with an On Click Event Procedure in my text
box with the following code...

Private Sub Resistance_Click()
RunCommand acCmdInsertHyperlink
End Sub

If you enter a hyperlink and press OK it works fine.
However if you click the Cancel button instead of entering
a hyperlink the debug error "The RunCommand action was
cancelled(Run-time error '2501')" appears. Is there a
work around to this???

Thanks David

Sure. Error 2501 is raised any time you initiate an action using VBA
code, and that action is subsequently cancelled. As a rule, you don't
really care about this, so you can set up error-handling in your code to
ignore that particular error:

Private Sub Resistance_Click()

On Error GoTo Error_Handler

RunCommand acCmdInsertHyperlink

Exit_Point:
Exit Sub

Error_Handler:
If Err.Number <> 2501 Then
MsgBox Err.Description, _
vbExclamation, "Error " & Err.Number
End If
Resume Exit_Point

End Sub
 

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