help with catching a cancel button

G

Guest

i have some really simple code on a button on my form that adds a hyperlink
to the field that i need it to and this button works for the times when a
user will select something in the dialog and then hits insert. but when a
user clicks cancel it gets a little trickier. how can i modify the code below
to make the cancel not cause an error?

Private Sub btnAddElectricalDiaLink_Click()
Me.ElectricalDiagrams.SetFocus
RunCommand acCmdInsertHyperlink
End Sub

thanks for the help
 
F

fredg

i have some really simple code on a button on my form that adds a hyperlink
to the field that i need it to and this button works for the times when a
user will select something in the dialog and then hits insert. but when a
user clicks cancel it gets a little trickier. how can i modify the code below
to make the cancel not cause an error?

Private Sub btnAddElectricalDiaLink_Click()
Me.ElectricalDiagrams.SetFocus
RunCommand acCmdInsertHyperlink
End Sub

thanks for the help

What is the error #?
Just trap it.

On Error GoTo Err_Handler
Me.ElectricalDiagrams.SetFocus
RunCommand acCmdInsertHyperlink
Exit_Sub:
Exit Sub
Err_Handler:
If err = xxxx Then
Else
MsgBox "Error #: " & Err.Number & " " & Err.Description
End If
Resume Exit_Sub

Replace xxxx with whatever error number is generated.
 
G

Guest

Hello

WOO HOO! My first error trapping code!

thanks for the help, a little tweaking and it worked beautifully for each
button.
 

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