Solved

ShellExecute VBA

Posted on 2014-01-10
5
1,924 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 51

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

734 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