Open file in native application

  • Thread starter Thread starter TJ Dowling
  • Start date Start date
T

TJ Dowling

I have a field that stores the path and filename of a document that is
related to the current record. I'm trying to give the user a button that
when clicked, will open the file in its native application similar to using
Windows Explorer and double-clicking on a filename.

How do I simulate this? I've tried the Shell() function but it expects an
executable and I may be passing an Excel or Word document instead of an exe.
Can SendKeys be used for this?

Thanks,
TJ Dowling
 
Create below and make sure you include below. Pete

************ Code Start **********
' This code was originally written by Dev Ashish.
' It is not to be altered or distributed,
' except as part of an application.
' You are free to use it in any application,
' provided the copyright notice is left unchanged.
'
' Code Courtesy of
' Dev Ashish

http://www.mvps.org/access/api/api0018.htm

Private Sub GetSpecs_Click()
On Error GoTo Err_GetSpecs_Click
Dim specsstring As String
Dim mypath As String
Dim strDBPath As String
Dim strDBFile As String
Dim strGoodFile As Integer
Dim CurrentDBDir As String
strDBPath = CurrentDb.Name
strDBFile = Dir(strDBPath)
CurrentDBDir = Left$(strDBPath, Len(strDBPath) - Len(strDBFile))
mypath = CurrentDBDir
specsstring = mypath & "Assetspecs\" & Me.ModelNumber & ".pdf"
Call fHandleFile(specsstring, Win_NORMAL)

Exit_GetSpecs_Click:
Exit Sub
Err_GetSpecs_Click:
MsgBox Err.Description
Resume Exit_GetSpecs_Click
End Sub
 
The code in the buttion on the fomr is:


Application.followHyperlink me!fieldname

It is ONE line of code....
 
This line worked:

Application.followHyperlink me!fieldname

I was looking at using the Win API ShellExecute() but this is much easier.

Thanks very much,
TJ Dowling
 
The code in the buttion on the fomr is:

Application.followHyperlink me!fieldname

It is ONE line of code....
Yes, that's much more simple than Dev Ashish's brilliant code.

I used Dev's code before the followHyperlink method appeared.
Sometimes I need to be prodded to upgrade.my mind. Thanks for doing
that, Albert.

Q
 
m:
I used Dev's code before the followHyperlink method appeared.
Sometimes I need to be prodded to upgrade.my mind.

FollowHyperlink was introduced at least in Access97 (if not in A95),
which was released in 1996. I strongly doubt that Dev's code was
posted on the Access Web before that. Indeed, the earliest
appearance of http://www.mvps.org/access/api/api0018.htm in the
Internet Archive (http://archive.org) is April 2000 (with a
copyright date of 2000). The Internet Archive doesn't post anything
until a site has been up for a year. Now, perhaps the Access web was
at a different location before then, but given that the copyright
date on the code is 1998-2000, it seems likely that Dev didn't set
up the site until 1998, long after FollowHyperlink was already
introduced in A97.
 
So, there are many reasons to use different methods depending on the
situation. Are you saying Dev's code was a waste of time? Follow hyperlink
has many problems if your network folks (Think they are gods) have a bug
somewhere!
 
Are you saying Dev's code was a waste of time?

No. I'm just pointing out that your timeline doesn't make sense.
Dev's code was apparently posted *after* .FollowHyperlink was
introduced. That doesn't mean *you* know about it (I, too, used
ShellExecute for a long time before noticing that .FollowHyperlink
was a useful alternative).
 
Back
Top