Application.Followhyperlink not working? (1 Viewer)

sherlocked

Registered User.
Local time
Today, 14:11
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?
 

isladogs

MVP / VIP
Local time
Today, 22:11
Joined
Jan 14, 2017
Messages
18,219
If using a UNC path, remove the colon after the drive letter
 

sherlocked

Registered User.
Local time
Today, 14:11
Joined
Sep 22, 2014
Messages
125
Thank you kindly but that did not solve the problem :(
 

Minty

AWF VIP
Local time
Today, 22:11
Joined
Jul 26, 2013
Messages
10,371
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:11
Joined
May 7, 2009
Messages
19,242
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")
 

sherlocked

Registered User.
Local time
Today, 14:11
Joined
Sep 22, 2014
Messages
125
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.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:11
Joined
May 7, 2009
Messages
19,242
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
 

sherlocked

Registered User.
Local time
Today, 14:11
Joined
Sep 22, 2014
Messages
125
Found the reference and added it but still getting a Run-time 490 error :(
 

MarkK

bit cruncher
Local time
Today, 14:11
Joined
Mar 17, 2004
Messages
8,181
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 05:11
Joined
May 7, 2009
Messages
19,242
Mr. Mvp again?@#$%&
 

static

Registered User.
Local time
Today, 22:11
Joined
Nov 2, 2015
Messages
823
Application.FollowHyperlink "file:\\S:\myfoldername", , True
 

MarkK

bit cruncher
Local time
Today, 14:11
Joined
Mar 17, 2004
Messages
8,181
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
 

static

Registered User.
Local time
Today, 22:11
Joined
Nov 2, 2015
Messages
823
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.
 

isladogs

MVP / VIP
Local time
Today, 22:11
Joined
Jan 14, 2017
Messages
18,219
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

Top Bottom