View a PDF from Access (1 Viewer)

Dangerous

Registered User.
Local time
Today, 12:08
Joined
Oct 18, 2018
Messages
73
I have several records that I would like to add a pdf file to. On clicking a button I can get the file to open externally (Adobe reader) but only if the file name is in the code. How would I get it to open the filename that is stored in a form control?

This code works

Private Sub Label1689_Click()

Application.FollowHyperlink "d:\MDF Database\Images\FileName.pdf"

End Sub

I tried

Private Sub Label1689_Click()

Dim strPDFfile As String
strPDFfile = [strPDFfile]
Application.FollowHyperlink strPDFfile

End Sub

But it fails, how to I get it to work?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:08
Joined
Aug 30, 2003
Messages
36,118
Presumably you need to add the path:

Code:
Application.FollowHyperlink "d:\MDF Database\Images\" & strPDFfile
 
Last edited:

June7

AWF VIP
Local time
Today, 04:08
Joined
Mar 9, 2014
Messages
5,425
The forum dropped the last \ in the path string before the concatenation.
 

Dangerous

Registered User.
Local time
Today, 12:08
Joined
Oct 18, 2018
Messages
73
The forum dropped the last \ in the path string before the concatenation.

I noticed that but the code still didn't work. I can add the file as a hyperlink and that does work.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:08
Joined
Aug 30, 2003
Messages
36,118
The forum dropped the last \ in the path string before the concatenation.

I don't think I can blame the forum. :banghead:

What exactly does the form control contain?
 

isladogs

MVP / VIP
Local time
Today, 12:08
Joined
Jan 14, 2017
Messages
18,186
Try using a different name for your variable and the form control
 

Dangerous

Registered User.
Local time
Today, 12:08
Joined
Oct 18, 2018
Messages
73
I don't think I can blame the forum. :banghead:

What exactly does the form control contain?

Testing with a file called FileName.pdf so the control contains FileName.pdf
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:08
Joined
Aug 30, 2003
Messages
36,118
The forum dropped the last \ in the path string before the concatenation.

Maybe I can blame the forum. Tried to add the backslash twice and it didn't save until I added code tags.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:08
Joined
Aug 30, 2003
Messages
36,118
Testing with a file called FileName.pdf so the control contains FileName.pdf

Then with the backslash added I'd expect it to work. It works if you hardcode that file name and path?
 

Dangerous

Registered User.
Local time
Today, 12:08
Joined
Oct 18, 2018
Messages
73
Then with the backslash added I'd expect it to work. It works if you hardcode that file name and path?

Yes, this works fine Application.FollowHyperlink "d:\MDF Database\Images\FileName.pdf"

but any record that needs a pdf linked to it will have its own specific file so hard coding not an option.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:08
Joined
Aug 30, 2003
Messages
36,118
So what does the code look like when you concatenate and get the error?
 

Dangerous

Registered User.
Local time
Today, 12:08
Joined
Oct 18, 2018
Messages
73
The reason I wanted to do it this way is so I could search the directory, select the file, and have it automatically store the file address. I wonder if I could do that in to a hyperlink control. Will have a go.
 

June7

AWF VIP
Local time
Today, 04:08
Joined
Mar 9, 2014
Messages
5,425
The VBA should work. If you want to provide db for analysis, follow instructions at bottom of my post.

@pbaldy, use code tags or on the Advanced editor window, uncheck "Automatically parse links in text". Has to be done every time a post is created or edited.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 05:08
Joined
Aug 30, 2003
Messages
36,118
You have to concatenate the fixed path and the variable. See my updated code in post 2.
 

Dangerous

Registered User.
Local time
Today, 12:08
Joined
Oct 18, 2018
Messages
73
I mean post the updated code from your first post.

Got you now.

Private Sub Label1689_Click()

Dim strPDFfile As String
strPDFfile = "D:\MDF Database\Images" & "strPDFfile"

Application.FollowHyperlink "d:\MDF Database\Images\FileName.pdf"

End Sub
 

Users who are viewing this thread

Top Bottom