Solved

ShellExecute VBA

Posted on 2014-01-10
5
1,805 Views
Last Modified: 2014-01-10
Hi Experts,

I'm using this VBA code and I'm trying to open a pdf file from MS Access 2007 form.


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



If I use this line no issues:

ShellExecute 0, "Open", "C:\Temp\myfile.pdf", "", "", vbNormalNoFocus



However this is what I need since the path name can change..

filename=CurrentProject.Path & "\myfile.pdf"


ShellExecute 0, "Open", filename, "", "", vbNormalNoFocus

Is that possible ?

Thank you,
0
Comment
Question by:valixpacc
  • 3
5 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39771163
have you tried

followhyperlink CurrentProject.Path & "\myfile.pdf"

if you want to use shell, you need to know the path to your pdf (acrobat ) reader
0
 
LVL 50

Assisted Solution

by:Rgonzo1971
Rgonzo1971 earned 150 total points
ID: 39771180
Hi,

You could declare Filename like this
Dim filename as String at the beginning of the code after the "sub" of function

Otherwise ther is no reason it won't function

Regards
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39771243
i think rgonzo is correct, sorry misread your post.
0
 

Author Comment

by:valixpacc
ID: 39771389
Thank you for your answers.
I already did that ( all variables are declared).
This won't solve the problem even I specify the full path of Acrobat Reader.

Again I wil explain:

Dim filename As String
filename = CurrentProject.Path & "\myfile.Pdf"


 '' no problem here

Shell "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe" & " " & "C:\Temp\myfile.pdf", vbNormalFocus


'' this is not working

Shell "C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe" & " " & filename, vbNormalFocus


OR


Application.FollowHyperlink "C:\Temp\myfile.pdf" -- working


Application.FollowHyperlink filename -- not working



So looks like no matter what approach I choose I need to specify the name of the file and the path instead of a variable wich doesn't solve the  issue.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 350 total points
ID: 39771498
are you sure there is a pdf file in the folder where your db application is located?

Dim filename As String
filename = CurrentProject.Path & "\myfile.Pdf"

debug.print filename

do this checking..

dim fName
fName= dir(currentproject.path & "\*.pdf")
while fName <>""
    debug.print currentproject.path & "\" & fName
    fName=dir
wend
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question