Opening PDF documents using a Command Button

G

Guest

Hi,
Like Colin before me, I need to open PDF documents in a form using a command
button and based on a variable ID number. I've put in the code that worked
for Cloin but it's not working for me. This is it below:

Dim strFileName As String

strFileName = "G:\Service Contracts\Declarations\" & Me.SerialNo & ".pdf"
Application.FollowHyperlink strFileSpec


I think it might be because of the hyperlink section of his code which I'm
not understanding correctly. If Colin or anyone else could help I'd be very
very grateful!

Kevin
 
R

Rick Brandt

Kevin said:
Hi,
Like Colin before me, I need to open PDF documents in a form using a
command button and based on a variable ID number. I've put in the
code that worked for Cloin but it's not working for me. This is it
below:

Dim strFileName As String

strFileName = "G:\Service Contracts\Declarations\" & Me.SerialNo &
".pdf" Application.FollowHyperlink strFileSpec


I think it might be because of the hyperlink section of his code
which I'm not understanding correctly. If Colin or anyone else could
help I'd be very very grateful!

Kevin

You set strFileName and then attempt to open strFileSpec. Is that your actual
code or a typo in the post? Also you do have these on separate lines right?
 
G

Guest

Hi,
That was the actual code that Colin had posted and yes they're on separate
lines. Here's how I've adapted it:

Private Sub OpenPDF_Click()
Dim strFileName As String

strFileName = "H:\ESMissionReports\" & Me.ID & ".pdf"
Application.FollowHyperlink strFileSpec

End Sub

I have the PDF files in a folder called 'ESMissionReports' and I want the
command button on my form to open the particular PDF based on the variable
'ID' field (which is also the autonumber for each record in my table and
query). So '91' in the ID field will open the PDF labelled '91' in
ESMissionReports' folder, etc.

Where exactly do I open 'strFileSpec'? I tried putting in a hyperlink
address in the Format tab of the properties section, but the hyperlink
address I entered there opened only the specific PDF.

I hope I've explained my problem well enough and thanks for your help.

Kevin
 
R

Rick Brandt

Kevin said:
Hi,
That was the actual code that Colin had posted and yes they're on
separate lines. Here's how I've adapted it:

Private Sub OpenPDF_Click()
Dim strFileName As String

strFileName = "H:\ESMissionReports\" & Me.ID & ".pdf"
Application.FollowHyperlink strFileSpec

End Sub
[snip]

You misunderstand. If that is verbatim code that you copied from somewhere then
the person who originally wrote it had a typo included. You are putting the
path of the file you want to open into one variable name and then you are using
a completely different variable name as the argument for FollowHyperlink. They
need to be the SAME.

If you had OPTION EXPLICIT set in your module (which you should) the code you
have there would not even compile.
 

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