Link to home
Start Free TrialLog in
Avatar of xerle
xerle

asked on

Unable to open hyperlinked file message

When I click on a hyperlink in a MS Access form, an 'Unable to open [filepath].  Cannot open the specified file.' message appears when the link is not valid (e.g. due to a broken network connection or deleted file).    Is there a way to intercept this message and provide a programmer defined message instead?  

As there are several reasons why a link may be invalid, I'd like to be able to provide users some guidance, in a more helpful message, on why the link may be broken and how to fix it .
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Are you getting runtime error 490, "cannot open specified file" ?  You can handle it (or any other specific error number like this:

On Error Goto EH
    '
    '  Your code goes here
    Exit Function   '** or sub
EH:
   if err.number = 490 then
    msgbox "Could not open file..."
  end if
end function
Avatar of xerle
xerle

ASKER

mbizup,

It probably isn't a runtime error as I have error trapping of the type you metioned throughout the application.  The message appears to be a Windows or MS Access system generated message that routinely appears when a user clicks on a broken hyperlink.  It seems to be more an indication of the state of the hyperlink than a runtime error.

Erle
If you are not getting a specific runtime error with a number, AFAIK you cannot trap it.  A workaround would be to change the field's datatype from hyperlink to text.  Then display that in a textbox on your form (you can use format properties of the textbox to make it look like a hyperlink).  Then use the FollowHyperlink command in the  textbox's click event to open it.  I believe this would give you a trappable runtime error:

Privete Sub txtYourHyperlinkText_Click()
On Error Goto EH
    '
    'This will follow the text 'hyperlink' displayed in your textbox.
    Application.FollowHyperlink me.txtYourHyperlinkText

    Exit Sub  
EH:
   if err.number = 490 then
    msgbox "Could not open file..."
  end if

end sub
Make a backup if you try that.
Also to get this to open in a new window, you would need this syntax:

Application.FollowHyperlink me.txtYourHyperlinkText,, True
                                                                                ^-- Open in new window (this argument's default is false)

(sorry for all the posts)
Avatar of xerle

ASKER

I have thought about using the wrokaround in the past, but the main disadvantage is that the built-in Edit Hyperlink dialog would not be displayed as it can be when you right click on a real hyperlink.   The Edit Hyperlink dialog doesn't seem to be mentioned in documentation on Common Dialogs either, so I haven't yet been able to figure out how to call it programmaticially and with a text hyperlink string as a parameter for the dialog.   Any idea how to do this?

       
SOLUTION
Avatar of mbizup
mbizup
Flag of Kazakhstan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> NOTE: docmd.cancelevent will not keep the event from firing.

No, that's why you should use the Key/Mouse-Down events.

/gustav
Avatar of xerle

ASKER

I also found that the event didn't always cancel, even when I used both Key and Mouse Down Events.  Switching the IsHyperlink property on/off was the main trick.  
Thanks to all for the contributions.

Erle
I found out. Jeff's solution only works for an unbound textbox.
If the textbox is bound to a field of type hyperlink, you must follow the other route.

/gustav
Avatar of xerle

ASKER

It looks like I accepted this question prematurely and didn't test the solutions well enough.   Is there a way to 'unaccept' the question and continue the thread?   I looked at the Question and Answer tips, but they don't seem to cover this case.

Erle
Not sure about the reopen thing, but what issue do you face?

/gustav
Gustav,
I tested my solution with bound textboxes...and I'll be happy to help still.

Erle
You can ask community support to reopen the question.
J
Avatar of xerle

ASKER

Jeff,

As you may have found when you tested your solution, the DoCmd.CancelEvent instruction does not stop Access attempting to open the hyperlink.  I need a way to stop Access attempting to open the hyperlink (ie. to not display an error message) when the hyperlink is not valid.

I will be away from my computer for the next two weeks (I can feel my hands shaking already) and may not be able to reply to any post until then.

Erle