Solved

ShellExecute VBA

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

Expert Comment

by:Rey Obrero
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 48

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 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now