Handling a user cancel with FollowHyperlink (AC2007) (1 Viewer)

AOB

Registered User.
Local time
Today, 02:48
Joined
Sep 26, 2012
Messages
615
Hi guys,

I have a continuous subform of attachments which includes a command button for the user to open/view the attachment in question. It's fairly straightforward :

Code:
Private Sub comViewAttachment_Click()
 
  On Error GoTo ErrorHandler
 
  Application.FollowHyperlink Me.txtAttachmentPath.Value
 
Exit_comViewAttachment_Click:
 
  Exit Sub
 
ErrorHandler:
 
  Call LogError(Err.Number, _
                 Err.Description, _
                 "comViewAttachment_Click", _
                 Me.Name, _
                 "AttachmentID : " & Me.txtAttachmentID.Value & "; Path : " & Me.txtAttachmentPath.Value)
 
  Resume Exit_comViewAttachment_Click
 
End Sub

However I noticed I was getting a number of errors logged, specifically :

Error 16388
The hyperlink cannot be followed to the destination

I got a bit worried but when I queried it with the various users under whose ID's the errors had been logged, they said nothing out of the ordinary had happened.

It's just dawned on me what's going on; when the user clicks on the button, there is a Microsoft Office security warning around opening a foreign file, along the lines of :

Opening XXX
Some files can contain viruses or otherwise be harmful to your computer.
It is important to be certain that this file is from a trustworthy source.
Would you like to open this file?

The dialog provides an OK / Cancel option. If the user clicks Cancel, this raises the error (even though technically nothing has really gone wrong - the user has opted not to open the file, rather than an actual failure to open the file at the described address)

I've no problem with the presence of the security warning (nor would I mind if it was bypassed altogether), but if it must remain, I would like to try to capture this scenario and not log any errors or prompt the user in a situation where they have opted to cancel out of the FollowHyperlink.

The only way I can think of is to put a condition in the error handler whereby if the error number is 16388, to just exit the routine (no prompt, no log). But I don't really like that as I'm guessing there could be situations where the user could choose OK but the hyperlink 'genuinely' couldn't be followed (for whatever reason), in which case I do want it prompted & logged. Or am I wrong? (would that result in a different error?)

I could also use ShellExecute instead of FollowHyperlink but I'd rather not incorporate API's and I'm not sure how it would handle .msg attachments either.

Any thoughts or suggestions?

Thanks

Al
 

AOB

Registered User.
Local time
Today, 02:48
Joined
Sep 26, 2012
Messages
615
Hi spike

I have googled it? At length? And that link doesn't give me any alternatives?

Add error handling to your procedure to trap and ignore the error

As you can see, I already have error handling in place, and one of the questions I asked was whether it would be safe to explicitly ignore error 16388, in order to continue to capture genuine issues with faulty hyperlinks and only bypass the handler in the event of a manual cancel

BTW, I would have expected error 2501 if the link was cancelled

I've debugged this, and a cancellation throws error 16388. Which brings me back to my question above?...
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 02:48
Joined
Sep 12, 2006
Messages
15,641
knowing that the error IS 16388 (yes, I might have expected 2051), I am sure you can safely dismiss error 16388.
 

AOB

Registered User.
Local time
Today, 02:48
Joined
Sep 26, 2012
Messages
615
Thanks guys - I was just looking for reassurance. To ease my concern, I've added a separate step to check the validity of the path prior to following the hyperlink, to reduce the likelihood that error 16388 is anything but a user-opted cancellation :

Code:
Private Sub comViewAttachment_Click()
 
  On Error GoTo ErrorHandler
 
  [COLOR=blue]If Len(Me.txtAttachmentPath.Value) > 0 Then[/COLOR]
 
[COLOR=blue]   If Len(Dir(Me.txtAttachmentPath.Value)) > 0 Then[/COLOR]
 
      Application.FollowHyperlink Me.txtAttachmentPath.Value, ,True
 
[COLOR=blue]   End If[/COLOR]
 
[COLOR=blue] End If[/COLOR]
 
Exit_comViewAttachment_Click:
 
  Exit Sub
 
ErrorHandler:
 
  [COLOR=blue]If Err.Number <> 16388 Then[/COLOR]
 
    Call LogError(Err.Number, _
                   Err.Description, _
                   "comViewAttachment_Click", _
                   Me.Name, _
                   "AttachmentID : " & Me.txtAttachmentID.Value & "; Path : " & Me.txtAttachmentPath.Value)
 
  [COLOR=blue]End If[/COLOR]
 
  Resume Exit_comViewAttachment_Click
 
End Sub
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 02:48
Joined
Sep 12, 2006
Messages
15,641
If Len(Dir(Me.txtAttachmentPath.Value)) > 0 Then

it's a good point. If the path does not exist at all, you get an error 54 I think.
 

Users who are viewing this thread

Top Bottom