Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to use Shell Function 1

Status
Not open for further replies.

riny

Technical User
May 15, 2000
32
0
0
FR
I have a field with a file name in it, the file could be any type (.doc/.xls/.tif/.mp3).

What I am trying to do is open it with the default software program (as it would double-clicking on it in windows explorer) with the "on double click" event.

I tried this but doesn't work:
-----------------
Private Sub InDocName_DblClick(Cancel As Integer)

Dim strFile As String
strFile = "c:\Windows\Explorer.exe " & "C:\Cendama\Riny\Inbox\" & Me![InDocName]
Dim RetVal
RetVal = Shell(strFile, 1)

End Sub
-----------------

Can anyone help pls?
Riny
 
In the declarations section:
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Public Const SW_SHOW = 3

Then:

Private Sub InDocName_DblClick(Cancel As Integer)
Dim strFile As String
dim rtrn as Long

strFile = "C:\Cendama\Riny\Inbox\" & Me![InDocName]
rtrn = ShellExecute (0, "open", strFile, vbNullString, vbNullString, SW_SHOW)

End Sub

This will open the file with whichever app is registered for that type.

Andy
 
Andy thanks so much!

It works beautifully, thank you so much!
Note I had to move the
Public Const SW_SHOW = 3
from declarations to the private sub (Const is not accepted in declarations).

Fyg whilst waiting for someone to help I browsed many forums and found this one liner method:

FollowHyperlink strFile

which worked, the only thing is you get a ms office warning dialog about virus safety, which you don't get with your code, so I am using your code.

I am very grateful for your help.
Riny
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top