Opening PDF to a Specific Page

1cekream

New member
Local time
Today, 11:02
Joined
Jul 18, 2011
Messages
3
Hi all,

I've been searching for a code that allows me to open up specific pages in a PDF file, through the click of a button in a form.

I have seen success with the following code:

Dim strPage As String, strFullPathToFile As String, strFullPathToAdobeReader As String
strFullPathToAdobeReader = "C:\Program Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32.exe"
strPage = "4"
strFullPathToFile = "F:\DatabaseMaterial\ViaSatellite2011Directory.pdf"
strFullCommandLine = """" & strFullPathToAdobeReader & """ /A page=" & strPage & "=OpenActions " & strFullPathToFile & """"
varRetVal = Shell(strFullCommandLine, vbNormalFocus)

However, I also want to be able to run this code under certain conditions & parameters. For example, I have added a field to the source table that has page numbers for each record. Whenever a certain record appears in the form, along with its corresponding page number, I want the code to open the PDF based on that information. Is this possible?

I would really appreciate it if someone could offer a solution! Thanks for your time in advance!
 
So you have a couple of controls on your form (myFrom), lets say txtPDFfile and txtPageNo.

Then the reference for these controls is:

[forms]![myForm].[txtPDFfile]

and

[forms]![myForm].[txtPageNo]


So you can use the above in your code:

Code:
Dim strPage As String, strFullPathToFile As String, strFullPathToAdobeReader As String
strFullPathToAdobeReader = "C:\Program Files (x86)\Adobe\Reader 9.0\Reader\AcroRd32.exe"
strPage = [forms]![myForm].[txtPageNo]
strFullPathToFile = [forms]![myForm].[txtPDFfile]
strFullCommandLine = """" & strFullPathToAdobeReader & """ /A page=" & strPage & "=OpenActions " & strFullPathToFile & """"
varRetVal = Shell(strFullCommandLine, vbNormalFocus)


Just to add...

If you are running the code from the form itself then you don't need to reference the form name. Instead you can use me:

me.txtPDFfile

Me.txtPageNo

If you are referencing subforms then it's a different matter. See here.

hth
Chris
 

Users who are viewing this thread

Back
Top Bottom