Solved

ShellExecute VBA

Posted on 2014-01-10
5
1,870 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
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 utilizing SQL Server stored procedures 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 Micr…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

740 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