Run Application

A

Alan

Hope some one can help

I have a command button on a form with the following code on it



Private Sub Command81_Click()
On Error GoTo Err_Command81_Click

Dim stAppName As String

stAppName = "C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe
d:\01.pdf"
Call Shell(stAppName, 1)

Exit_Command81_Click:
Exit Sub

Err_Command81_Click:
MsgBox Err.Description
Resume Exit_Command81_Click

End Sub


What I would like it to do is to get the path and file name from a text
field on the same form as the command button. How do I insert a reference
to this text field after the Acrobat.exe so it opens the file when it loads.
Have tried various options putting the text field name in brackets i.e.
[PathToFile] after the Acrobat.exe but it cannot find the file. Any help
or pointers would be great. Or is there a better way to open a Acrobat PDF
file from a command button in Access.
 
A

Allan Murphy

Alan

Try this
Add a text box to your form call it file_path

Enter the full path and filename
e.g. d:\downloads\47s.pdf

Private Sub Command81_Click()
On Error GoTo Err_Command81_Click

Dim stAppName As String
Dim file_path as string

file_path = me!file_path

stAppName = "C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe " &
file_path

Call Shell(stAppName, 1)

Exit_Command81_Click:
Exit Sub

Err_Command81_Click:
MsgBox Err.Description
Resume Exit_Command81_Click

End Sub
 
V

Van T. Dinh

Try:

Shell Chr$(34) & strAppName & Chr$(34) & " " & _
Chr$(34) & Me.PathToFileTextBox & Chr$(34), vbNormalFocus
 
A

Alan

Thanks for the help. One little extra please.

Could the code be adjusted so that it checks the [path] text box to see if
there is a Path to the PDF file and if not it brings up a message box saying
"NO Image Found" and then the action is cancelled. Below is the code I have
so far: If I click my command button with no path in the path text box
then I get an error message. Invalid Use Of Null

Private Sub Command81_Click()
On Error GoTo Err_Command81_Click

Dim stAppName As String
Dim Tpath As String

Tpath = Me!path

stAppName = "C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe " &
Tpath
Call Shell(stAppName, 1)

Exit_Command81_Click:
Exit Sub

Err_Command81_Click:
MsgBox Err.Description
Resume Exit_Command81_Click

End Sub




Van T. Dinh said:
Try:

Shell Chr$(34) & strAppName & Chr$(34) & " " & _
Chr$(34) & Me.PathToFileTextBox & Chr$(34), vbNormalFocus

--
HTH
Van T. Dinh
MVP (Access)


Alan said:
Hope some one can help

I have a command button on a form with the following code on it



Private Sub Command81_Click()
On Error GoTo Err_Command81_Click

Dim stAppName As String

stAppName = "C:\Program Files\Adobe\Acrobat 7.0\Acrobat\Acrobat.exe
d:\01.pdf"
Call Shell(stAppName, 1)

Exit_Command81_Click:
Exit Sub

Err_Command81_Click:
MsgBox Err.Description
Resume Exit_Command81_Click

End Sub


What I would like it to do is to get the path and file name from a text
field on the same form as the command button. How do I insert a
reference
to this text field after the Acrobat.exe so it opens the file when it loads.
Have tried various options putting the text field name in brackets i.e.
[PathToFile] after the Acrobat.exe but it cannot find the file. Any
help
or pointers would be great. Or is there a better way to open a Acrobat PDF
file from a command button in Access.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top