Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Access - attaching a pdf file to a form 2

Status
Not open for further replies.

dolodolo

Technical User
May 27, 2003
86
US
Hi,

I am trying to attach a pdf file to a form. This is what I have going right now:

tblImage - has the image name, jpg path and filename, pdf path and file name.

form: 1 button brings up the jpg image. No problem I have also added a report button to print out that image.

The problem is that the pdf file is larger than the space I have allocated and I'd like to give the user the option to access that file as well. (It's a CAD layout and the jpg version is pretty small.) How can I attach the file (attached to the imageID in the tblImage) to a button on the form that will bring it up in preview mode?

Thanks for any and all help,
Dolores
 
Hi Dolores,

Word can't display the contents of a PDF file. There is a way around this, however. Check out the code I posted in the thread at:
That code allows you to insert an object and display it as an icon. If you base your code on that, all your user will need to do is to double-click on the icon to get the pdf to display. This approach also means the pdf will have to be inserted into an unprotected Section (otherwise your user won't be able to click on it).

Cheers

[MS MVP - Word]
 
If you have acrobat reader installed, you should find Adobe Acrobat Browser control (AcroPDF.dll). It can be added to the form (userform) and customised. Code in userform:
Code:
Private Sub CommandButton1_Click()
With Me.AcroPDF1
    .LoadFile "FullPath\FileName.pdf"
End With
End Sub

combo
 
With VBA access you may consider the Application.FollowHyperlink method.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Hi Combo,

Here's my code:

Private Sub Command20_DblClick(Cancel As Integer)

With Me.AcroPDF1
.LoadFile "G:\1 Procurement\National Contracts\Fitness Equipment\Images\den1133-layout.pdf"
End With
End Sub

What do I substitute AcroPDF1 with? Do I need to declare a variable for the file name?

Thanks for your help
 
What about this ?
Code:
Private Sub Command20_DblClick(Cancel As Integer)
FollowHyperlink "G:\1 Procurement\National Contracts\Fitness Equipment\Images\den1133-layout.pdf"
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks that worked great.

Now I need to set variables so that I can have these look to the table rather than hardcode a path and file name. I also need the image to be attached to the record being viewed. Would I use the [me!filename] approach?

Thanks all very much.
 
here's my attempt at using variables and I'm not defining my variable properly:

Private Sub Command20_DblClick(Cancel As Integer)
Dim strFileName As String
strFileName = Me!FileName
FollowHyperlink (strFileName)
End Sub

I'm receiving an error on the Me!Filename. The field is tblImage.filename.

Any help is much appreciated. Thanks all!
 
Which error ?
Is the form bound to tblImage ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
it just highlighted the line in Yellow.

Yes the record source for the form is 'tblImage'
 
Hi Dolores,

While not wanting to take anything away from the hyperlink & acrobat activation solutions you've been given, it's important to note that they'll only work for users who haver access to the folder on which the target file is stored. Amongst other things, that means those solutions won't work if the target file is stored on an unshared local drive or a network drive to which the document recipient doesn't ordinarily have access. Nor will they work if the document is emailed to anyone outside your organisation, or if the file paths get changed.

Embedding the pdf in your document is the most reliable way of overcoming those limitations. If your document has a userform, you could use a button on that to open the embedded file.

Cheers

[MS MVP - Word]
 
Yes the record source for the form is 'tblImage'
What are the field(s) and/or control(s) names holding the pdf pathname ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Concerning Acticex control:
I guess that you can add 'Adobe PDF Reader' from the toolbox toolbar to the form (should be available in the full list of controls). You can change its default name (AcroPDFx) in the properties window.
The real name of this control can be used in the code.
You can navigate to the file in the same way as in case of hyperlink:
Code:
With Me.ControlNameHere
    .setShowToolbar False
    .LoadFile strFileName
End With
After fixing assess to the file path, you need (hyperlink option):
Code:
FollowHyperlink strFileName


combo
 
the field name holding the pdf path and filename is [tblImage].[filename].

Thanks
 
Use an hidden textbox named, say, txtFileName, bound to tblImage.filename and then:
Code:
Private Sub Command20_DblClick(Cancel As Integer)
If Trim(Me!txtFileName & "") <> "" Then
  FollowHyperlink Me!txtFileName
End If
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top