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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open PDF using Command Button and a Text Box 6

Status
Not open for further replies.

cpc06

Technical User
Dec 13, 2007
5
GB
I'm sure this has been explained elsewhere but I can't seem to find it. I am using Access to store a number of academic references. I have a form that displays each reference's unique ID and various pieces of information about it.

I am storing all the pdfs in a folder called "C:\References", saving them in the format: "IDauthorDATE". One text box in the database is called "PDF Link" and I am recording the IDauthorDATE text there.

How do I create a Command Button event that will open the pdf corresponding to the current record (i.e. merge the folder and the pdf file text and open that file)?

n.b. I don't want to put the whole string in the text box in case I have to move the whole folder in the future.

Many thanks.
 
Application.FollowHyperlink "C:\References\" & IDAuthorDate & ".PDF"

John
 
Thanks. Forgive my ignorance, but what is the actual code that I need to put in place of IDAuthorDate so that it uses the text stored in a text box called "PDF link"? With the text as it is, it just tries to open "C:\References\.pdf", rather than, say, "C:\References\137Smith1999.pdf" when 137Smith1999 is in the "PDF Link" text box.
 
FollowHyperlink "C:\References\" & Me![PDF link] & ".PDF"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You put the name of the textbox in place of IDAuthorDate.

As the textbox has a space in its name, you need to enclose that in square brackets, thus:

Application.FollowHyperlink "C:\References\" & Me![PDF Link] & ".PDF"

John
 
what i do is in the oncurrent event of the form
Code:
Me.BtnViewpdf.HyperlinkAddress = "C:\References\" &  Nz(Me![PDF Link], "") & ".PDF"
 
pwise - that will work, provided that there is text in the PDF Link field.

If there is no text, you will end up with a link trying to open a file called .pdf in that folder.

Better to do something like:

Code:
If Len (Me![PDF Link] & "") > 0 Then
  Me.BtnViewpdf.HyperlinkAddress = "C:\References\" &    Nz(Me![PDF Link], "") & ".PDF"
Else
  Me.BtnViewpdf.HyperlinkAddress = ""
End If

That way, no hyperlink if there's no data.

John
 
jrbarnett:
You are right!
this i copied from my code

Code:
Me.BtnViewIep.HyperlinkAddress = Nz(Me!Studentpath + Me.IEPFilename, "")

Note: That I combine the path and the file name with a "+" not a "&" that if the IEPFilename is Null it returns a null and I change it to a empty string with the Nz function
 
Thanks for everyone's help. I have it working now. But...

The command button now works fine on my computer, but the database is stored on a shared drive (as is the folder I am asking it to refer to) and the link doesn't work for someone else using the database on a different computer. On clicking the buttone, Adobe opens for a split second and then shuts down, whereas when I do exactly the same thing on my computer, the correct file opens perfectly. As far as I know, nothing in the code refers specifically to my computer, only to things on the shared area. The code I'm using is:

Private Sub Command82_Click()
Application.FollowHyperlink CurrentProject.Path & "\References\" & Me![PDF Link].Value & ".PDF"
End Sub

Any ideas? Thanks again for all the help so far!
 
Is CurrentProject.Path a UNC one (eg \\server\share\mydatabase.mdb) or a mapped one (eg z:\share\mydatabase.mdb?)

If it uses a mapping, this needs to be the same on all computers - preferably set using a login script.

John
 
I'm not sure. The path seems to be in the "\\server\share" format, but I also have mapped it onto my desktop.

Is there a more robust way of doing relative links in access, so it never matters where the files are stored, as long as their relative position to the database is maintained?
 
UNC is better than mappings, unless you have login scripts to enforce the mappings at login.

Do the people that who use this (bar you) have the same permissions in this folder (both NTFS and share) as you?

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top