Application.Followhyperlink not working?

sherlocked

Registered User.
Local time
Today, 10:31
Joined
Sep 22, 2014
Messages
125
Experts,

I have the following code in two different databases:

Code:
Application.FollowHyperlink "\\S:\myfoldername", , True

In one of my databases, this works totally fine. In another, I get the following error message:

Run-time error 490 - Cannot Open The Specified File.

I have already verified that the path is correct in this second instance. I can navigate through manually and the shared folder location I'm looking for exists and the permissions to access it are correct.

Any idea as to why this same function would work in one database and not in another?
 
If using a UNC path, remove the colon after the drive letter
 
Thank you kindly but that did not solve the problem :(
 
You would be better to use a full UNC path e.g. \\yourserver\yourfolder\ rather than a mapped drive letter, if the drive hasn't been mapped on any system using the database that code would fail.

In addition to removing the colon you also probably should add a trailing slash as above.
 
Same answer to your other post

You can try to covert the mapped drive
Code:
Function GetUNC(strMappedDrive As String) As String
    Dim objFso As FileSystemObject
    Set objFso = New FileSystemObject
    Dim strDrive As String
    Dim strShare As String
    'Separated the mapped letter from
    'any following sub-folders
    strDrive = objFso.GetDriveName(strMappedDrive)
    'find the UNC share name from the mapped letter
    strShare = objFso.Drives(strDrive).ShareName
    'The Replace function allows for sub-folders
    'of the mapped drive
    GetUNC = Replace(strMappedDrive, strDrive, strShare)
    Set objFso = Nothing 'Destroy the object
End Function
Then call it:

Application.FollowHyperlink GetUNC("S:\myfoldername")
 
Thanks for this. Is there a reference I must add to my DB to allow this? I am getting a "user defined type not defined" at the FileSystemObject line. Assuming my DB doesn't have the right references.
 
hello, i tried my own code and found that it's sometimes working and sometimes not.
but this one always work

to call:
Code:
Dim strUNC as string
strUNC = GetMappedDriveUNC("S:")
' for test only. comment out the proceeding line
debug.print strUNC
Application.FollowHyperlink strUNC & "\the path here"

Code:
Function GetMappedDriveUNC(strDrive)
   Dim objNetwork As Object
   Dim objDrives As Variant
   Dim strNetDrive As String
   Dim strNetPath As String
   Dim i As Long
   Set objNetwork = CreateObject("WScript.Network")

   Set objDrives = objNetwork.EnumNetworkDrives
   For i = 0 To objDrives.Count - 1 Step 2
      strNetDrive = objDrives.Item(i)
      strNetPath = objDrives.Item(i + 1)
      If UCase(strNetDrive) = UCase(strDrive) Then
          GetPath = strNetPath
          Exit For
      End If
   Next

   Set objNetwork = Nothing
End Function
 
Found the reference and added it but still getting a Run-time 490 error :(
 
Sherlock that code is way overkill. Arnel has a reputation for throwing a ton of VBA at simple problems. Just find the string that will work with your Application.FollowHyperlink. I can get it to work on a mapped drive on my machine using...
Code:
FollowHyperlink "z:\"                  [COLOR="Green"]'opens windows explorer to the z:\ (mapped) drive[/COLOR]
FollowHyperlink "z:\ColumnChart.html"  [COLOR="green"]'opens the html file in a browser[/COLOR]
FollowHyperlink "z:\somefolder         [COLOR="green"]'opens windows explorer to that folder[/COLOR]
FollowHyperlink "z:\folder\image.gif" [COLOR="green"] 'opens the image in an editor[/COLOR]
Experiment with some strings using FollowHyperlink, I bet you will find something that works.
hth
Mark
 
Mr. Mvp again?@#$%&
 
Application.FollowHyperlink "file:\\S:\myfoldername", , True
 
Mr. Mvp again?@#$%&
I think your solution is too complicated for the problem. I respect your right to disagree, and I apologize if in making my point I have hurt you, because that is not my intent. But I care about this place, and I have been committed to making it a better place since 2004. If I think you are giving bad advice, I reserve the right to say so, and to offer something that I think is better, which is what I have done in this thread. How you deal with that is up to you. You can learn something, you can ignore me, you can try insult me, your call, but keep in mind, whatever you choose reflects on you.

Thanks for all you contribute around here, but know that where I think your contribution is incorrect, misleading, or overly complicated, it is absolutely my place to say so, and I will not shy away from that because your feelings.

My intention is that information on this site is accurate and useful, with room for debate on the issues where there are differences of opinion. I invite you to work with me, and with others on this site, to make that come true.

All the best going forward arnelgp,
Mark
 
Regardless of your opinion; if a drive is a network share you should use UNC.

Of course you should SAVE the mapping as UNC, not try to convert S: to UNC after the fact.
 
Regardless of your opinion; if a drive is a network share you should use UNC.

Of course you should SAVE the mapping as UNC, not try to convert S: to UNC after the fact.

I agree with both of the above

However, I always use code like this:
Code:
Application.FollowHyperlink "\\ComputerName\S\myfoldername", , True

rather than the code static suggested
Code:
Application.FollowHyperlink "file:\\S:\myfoldername", , True

Both work. Is there any advantage in one over the other?
 
Last edited:

Users who are viewing this thread

Back
Top Bottom