Question Locked

Access and PDF

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I?m trying to use MS Access and VBA to open a PDF file in Reader and go to a specific page. I?m using OLE Automation to try to use the AcroPDF.dll library and it?s methods, such as ?LoadFile? and ?SetCurrentPage? which should do what I want. But I can?t seem to get the code right to reference the AcroPDF library and get its methods to work. I?ve gone to Tools|References and set up a reference to Adobe Reader 7.0 which refers to that library, but the methods still don?t work.

Does anyone know how to use VBA to establish the reference and correctly use methods?

Thanks.

8 replies

by bschaettle

Acrobat command line parameters are documented here:

http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf

To open the PDF file, use a shell, as shown here.

Sub Open_PDF_To_Page()
Dim RetVal
Dim cmd As String
Dim Fullpath As String
Dim PageNum As Integer
Fullpath = "C:\...\SomeFile.pdf"
PageNum = 3
cmd = Chr(34) & "C:\Program Files\Adobe\Acrobat 7.0\reader\AcroRd32.exe" & Chr(34) & _
" /a " & _
Chr(34) & "page=" & PageNum & Chr(34) & " " & _
Chr(34) & Fullpath & Chr(34)
RetVal = Shell(cmd, 1)
End Sub

by erodriguez

I like your code and I am attempting something similar in AccessVB.

I can open a specific PDF located in a directory on the server using this piece of code:

Private Sub HLINK_Click()
Dim pdffile As String
pdffile = HLINK 'This field contains the text string with the full file path to the pdf'
Shell "C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe " & pdffile
End Sub

My problem is what if the user has Acrobat 5.0 or 7.0? How can make it so that it launches the currently installed version of Acrobat?

by erodriguez

I like your code and I am attempting something similar in AccessVB.

I can open a specific PDF located in a directory on the server using this piece of code:

Private Sub HLINK_Click()
Dim pdffile As String
pdffile = HLINK 'This field contains the text string with the full file path to the pdf'
Shell "C:\Program Files\Adobe\Acrobat 6.0\Reader\AcroRd32.exe " & pdffile
End Sub

My problem is what if the user has Acrobat 5.0 or 7.0? How can make it so that it launches the currently installed version of Acrobat?

by bschaettle

I have some VBScript code that should help. I'm not at the office until next week; I'll post it then.

by erodriguez

Took your reply and did search on it and came across the below code:

GetApplicationPath - Retrieve the path of a Windows application from the Registry
Const HKEY_LOCAL_MACHINE = &H80000002

' Get the path of a Windows application
' or an empty string if the application isn't registered
'
' this routine only works for those applications that register
' themselves under the registry key
' HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\App Paths
'
' You can use it to retrieve the path of all MSOffice apps,
' MS Access, SQl Server, Windows Dialer, and more, for example
' ' Run Excel in a maximized window
' Shell GetApplicationPath("EXCEL.EXE"), vbMaximizedFocus
'
' requires the GetRegistryValue function

Function GetApplicationPath(ByVal ExeName As String) As String
GetApplicationPath = GetRegistryValue(HKEY_LOCAL_MACHINE, _
"Software\Microsoft\Windows\CurrentVersion\App Paths\" & ExeName, "")
End Function

It does not work because when I compile the function, i get an error that the function is not defined.

by post

This is my code for opening av PDF-file from an Access (2003) Form:

Dim PDFVedlegg As String
PDFVedlegg = G_VedleggKatalog & S?knads?r & "\" & VedleggFilPDF

Application.FollowHyperlink PDFVedlegg, , True

This discussion is closed to new replies.