Shell

M

Mike Revis

Hi Group,
Access 2000. Win xp pro.

In my efforts to find a way to open a file in Access I found the following
code.

Private Sub cmdViewTechSheet_Click()
'Open the Tech Sheet file.

Dim stAppName As String
Dim FilePath As String

FilePath = Me!FilePath

stAppName = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe " &
FilePath

Call Shell(stAppName, 1)

End Sub

FilePath is a text field on my form in which the file path has been entered
in the form \\ServerName\ShareName\FileName.pdf.

This works well as long as the file path has been entered correctly.

There is another field on the form called ProductCode that has the product
code which also happens to be the file name that I want to open.

What I would like to accomplish is to have the "FilePath" pull the product
code from the ProductCode field.

Something along the lines of FilePath = \\ServerName\ShareName\ &
[ProductCode] & ".pdf"

As always any thoughts, comments or suggestions are welcome.

Mike
 
A

Andrew Smith

Mike Revis said:
Hi Group,
Access 2000. Win xp pro.

In my efforts to find a way to open a file in Access I found the following
code.

Private Sub cmdViewTechSheet_Click()
'Open the Tech Sheet file.

Dim stAppName As String
Dim FilePath As String

FilePath = Me!FilePath

stAppName = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe " &
FilePath

Call Shell(stAppName, 1)

End Sub

FilePath is a text field on my form in which the file path has been
entered
in the form \\ServerName\ShareName\FileName.pdf.

This works well as long as the file path has been entered correctly.

There is another field on the form called ProductCode that has the product
code which also happens to be the file name that I want to open.

What I would like to accomplish is to have the "FilePath" pull the product
code from the ProductCode field.

Something along the lines of FilePath = \\ServerName\ShareName\ &
[ProductCode] & ".pdf"

As always any thoughts, comments or suggestions are welcome.

Mike

What you've written should work perfectly well, but you'll need to enclose
the folder name in parentheses or define it as a variable. If the path is
fixed and unlikely to change too often then I'd probably declare it as a
constant at the top of the procedure:

Private Sub cmdViewTechSheet_Click()
'Open the Tech Sheet file.

Dim stAppName As String
Dim FilePath As String
const cstrPath as string = "\\ServerName\ShareName\ "

FilePath = cstrPath & [ProductCode]

stAppName = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe " &
FilePath

Call Shell(stAppName, 1)

End Sub
 
M

Mike Revis

Andrew,
Thank you for your response.

I wrote the code exactly as in your example but kept getting a "the file
cannot be found" error after acrobat opened.

This might be obvious to most folks but I'm a little slow when it comes to
vba.

I finally figured out that I had to add & ".pdf" to the end of the line
FilePath = cstrPath & [ProductCode].

So FilePath = cstrPath & [ProductCode] returned the error but FilePath =
cstrPath & [ProductCode] & ".pdf" works like a champ.

Thanks for pointing me in the right direction.

Mike







Andrew Smith said:
Mike Revis said:
Hi Group,
Access 2000. Win xp pro.

In my efforts to find a way to open a file in Access I found the following
code.

Private Sub cmdViewTechSheet_Click()
'Open the Tech Sheet file.

Dim stAppName As String
Dim FilePath As String

FilePath = Me!FilePath

stAppName = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe " &
FilePath

Call Shell(stAppName, 1)

End Sub

FilePath is a text field on my form in which the file path has been
entered
in the form \\ServerName\ShareName\FileName.pdf.

This works well as long as the file path has been entered correctly.

There is another field on the form called ProductCode that has the product
code which also happens to be the file name that I want to open.

What I would like to accomplish is to have the "FilePath" pull the product
code from the ProductCode field.

Something along the lines of FilePath = \\ServerName\ShareName\ &
[ProductCode] & ".pdf"

As always any thoughts, comments or suggestions are welcome.

Mike

What you've written should work perfectly well, but you'll need to enclose
the folder name in parentheses or define it as a variable. If the path is
fixed and unlikely to change too often then I'd probably declare it as a
constant at the top of the procedure:

Private Sub cmdViewTechSheet_Click()
'Open the Tech Sheet file.

Dim stAppName As String
Dim FilePath As String
const cstrPath as string = "\\ServerName\ShareName\ "

FilePath = cstrPath & [ProductCode]

stAppName = "C:\Program Files\Adobe\Acrobat 7.0\Reader\AcroRd32.exe " &
FilePath

Call Shell(stAppName, 1)

End Sub
 
A

Andrew Smith

I finally figured out that I had to add & ".pdf" to the end of the line
FilePath = cstrPath & [ProductCode].

So FilePath = cstrPath & [ProductCode] returned the error but FilePath =
cstrPath & [ProductCode] & ".pdf" works like a champ.

Thanks for pointing me in the right direction.

Yes, you would need to do that.

You can easily add a line to check for the existence of the file before
trying to open it by using the dir command, eg something like this:

if len(dir(FilePath)) > 0 then
'code here to open the file
else
msgbox "No such file"
end if
 
M

Mike Revis

That's a good idea. Might save some grief later on.

Thanks again.

Mike


Andrew Smith said:
I finally figured out that I had to add & ".pdf" to the end of the line
FilePath = cstrPath & [ProductCode].

So FilePath = cstrPath & [ProductCode] returned the error but FilePath =
cstrPath & [ProductCode] & ".pdf" works like a champ.

Thanks for pointing me in the right direction.

Yes, you would need to do that.

You can easily add a line to check for the existence of the file before
trying to open it by using the dir command, eg something like this:

if len(dir(FilePath)) > 0 then
'code here to open the file
else
msgbox "No such file"
end if
 

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