How can I open a PDF document from an Access database form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have several documents stored as PDF documents. I wish to open a PDF
document by clicking a button in an Access form. Please help.
 
You can use the FollowHyperLink, it will open any file with the program
assocuated with it in windows

Application.FollowHyperLink "File Path and name"

e.g

Application.FollowHyperLink "c:\Filename.pdf"
 
Using the hyperlink method works most of the time but I have had problems
with the department that supplies the PDF document. They do not always use
the same naming convention when creating the Pdf. If there is a comma or a
pound sign (#) in the file name of the PDF the hyperlink may not always work.
In my work place the PDF’s are scanned images of contractual documents. These
come in three flavors; Proposed, Authorized, and Cancelled.
I have solved the hyperlink problem by doing the following, one by creating
a field in one of the forms supporting tables called “FileName†in this field
I paste the name of the pdf document from the Pdf’s properties box.
On the form itself I have an unbound text box. Using the On current property
of the form I have an if statement that creates one of the folder names that
contract’s uses to file the pdf. For example A1 = authorized, p1 = proposed,
C1 = cancelled.

Private sub Form_current()
If Authcode.value = “A1†then
Me.txtFolder= “ContractxxxAuthorizedâ€
End if
Elseif Authcode.value=â€P1†then
Me.txtfolder=â€contractXXXProposedâ€
End if
Elseif Authcode.value=â€C1†then
Me.txtFolder=â€contractxxxCanceledâ€
End if
Exit sub
End sub

Create a button on your form with the code below:

Private Sub cmdViewPDF_Click()
' this sub opens a particular Pdf based on information contained on
Document tracking ‘information form.
Dim strAdd As String
strAdd = txtFolder & "\" & FileName
OpenPDFFile "\\ServerName\PF1\Pf2\Pf3\PF4\PDFs\" & strAdd & " "
Exit Sub


End Sub

PF1= primary Folder
Pf2=Secondary Folder
PF3= tertiary Folder
Pf4= next folder
Etc.
Thus with these two sets of code you set up a way to open a PDF document by
programming in the file path and not using the hyperlink.

Good luck
 

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

Back
Top