FollowHyperlink to file regardless of extension (1 Viewer)

JustinB

Registered User.
Local time
Today, 00:20
Joined
Dec 13, 2012
Messages
14
I am trying to create some code for a button in a report that will follow a hyperlink to a specific file. The problem I'm having is that the files that are at the end of the hyperlink can have various extensions (*.doc, *.docx, *.pdf, etc.) I'd like to be able to put a wildcard in the code to allow the opening of the file regardless of the extension. Is there a way to do this?

Code so far:

Private Sub Command6_Click()

Application.FollowHyperlink ("C:\Users\jbegg\Documents\AccessTestFolder\" & [FileName] & ".*")
End Sub

Any help or direction will be greatly appreciated.
 

pr2-eugin

Super Moderator
Local time
Today, 05:20
Joined
Nov 30, 2011
Messages
8,494
So if a file has several extensions then which file would take precedence?
 

JustinB

Registered User.
Local time
Today, 00:20
Joined
Dec 13, 2012
Messages
14
Fortunately, there are no instances of file extension precedence possibilities. This folder is a storage location. Some files are stored as *.doc, some of the newer files are stored as *.docx or *.pdf.
 

spikepl

Eledittingent Beliped
Local time
Today, 06:20
Joined
Nov 3, 2010
Messages
6,142
I'd use the function Dir (look it up) to see which version exists and open that one using FollowHyperlink. Assuming that wildcard doesn't work. Does it?
 

pr2-eugin

Super Moderator
Local time
Today, 05:20
Joined
Nov 30, 2011
Messages
8,494
Okay create a custom function, I think you would need the method proposed by Allen Browne to List the files recursively. Change it a bit, to loop through the files matching the part of the filename. Then just simply use Application.Hyperlink to the first found file..
 

JustinB

Registered User.
Local time
Today, 00:20
Joined
Dec 13, 2012
Messages
14
I'd use the function Dir (look it up) to see which version exists and open that one using FollowHyperlink. Assuming that wildcard doesn't work. Does it?

For some reason, the wildcard function doesn't work, but I feel that I'm using it improperly.

I will look up the Dir function and see if that can be applied. I will post the outcome on this thread.

Thanks,
 

GinaWhipp

AWF VIP
Local time
Today, 00:20
Joined
Jun 21, 2011
Messages
5,899
Give this a try...

Code:
Dim strFileName As String
 
strFileName = Dir("C:\Users\jbegg\Documents\AccessTestFolder\" & Me.FileName & "*")
 
Application.FollowHyperlink ("C:\Users\jbegg\Documents\AccessTestFolder\" & strFileName)
 
Last edited:

JustinB

Registered User.
Local time
Today, 00:20
Joined
Dec 13, 2012
Messages
14
Give this a try...

Code:
Dim strFileName As String
 
strFileName = Dir("C:\Users\jbegg\Documents\AccessTestFolder\" & Me.FileName & "*")
 
Application.FollowHyperlink ("C:\Users\jbegg\Documents\AccessTestFolder\" & strFileName)

This worked perfectly. It appears that you cannot call a wildcard in the Application.FollowHyperlink. Calling it in the string made it work wonderfully. Thanks for your help.
 

GinaWhipp

AWF VIP
Local time
Today, 00:20
Joined
Jun 21, 2011
Messages
5,899
No problem... and no you can't, the FollowHyperlink does not understand *Wildcard*. Thanks for posting that, I should have! :banghead:
 

databasedonr

Registered User.
Local time
Today, 00:20
Joined
Feb 13, 2003
Messages
163
Thanks GinaWhipp - I was searching forums for a solution to storing multiple file format hyperlinks, and this worked a treat. I've also discovered your website as a result, which is now bookmarked as a resource for me.

Thanks again!
 

GinaWhipp

AWF VIP
Local time
Today, 00:20
Joined
Jun 21, 2011
Messages
5,899
@databasedonr

Glad you found that helpful (both the post and the website)!
 

databasedonr

Registered User.
Local time
Today, 00:20
Joined
Feb 13, 2003
Messages
163
Oh, absolutely. I had coded an MS-Word-specific solution, but my clever users started attaching Outlook messages and PDFs, which didn't work so well. This elegant solution allowed me to change one line of code and look like a genius in under 10 minutes - mostly thanks to you and your post.

Sadly, your website is likely to get me in trouble - there is a ton of useful stuff there! I'll be reading your tips when I should be working...

Thanks again, have a great week-end, and keep up the good - no great - work!
 

Users who are viewing this thread

Top Bottom