linking to pdf-files in a folder

brother

Programmer
Local time
Today, 17:02
Joined
Mar 30, 2009
Messages
40
Hi,

We have a database at work with a register of all the chemicals we use on a daily basis. Each of these chemicals comes with a pdf document specification. All of these documents are stored in the folder C:\chemicals\pdf\.

What I'm working on is a way to connect each record in the database to the corresponding pdf document in the folder. The filename of each document is the same as the autoID of the record in the database. ex. 5013.pdf.

So far i have come up with the following code in the on_click event of a pdf icon image in the main form:

Code:
Private Sub pdfico_Click()
On Error GoTo ErrorMessage
 
FollowHyperlink "C:\Chemicals\pdf\" & Me.ChemID & ".pdf"
 
Exit_pdfico_Click:
    Exit Sub
 
ErrorMessage:
MsgBox "Can't find document."

End Sub

This code works fine, but I want to hide the pdf icon (which contains the on_click event) on my form if the code cant find a document with that same ChemID number.

This could perhaps be done throught Form_Open?

Could anyone of you maybe slip me a line of code to help me on my way?

thanks!
 
If you use the on current event of the form and enter

Code:
If Dir("C:\Chemicals\pdf\" & Me.ChemID & ".pdf")= "" Then
   Me.Icon.Visible = False
Else
   Me.Icon.Visible = True
End If

Where Me.Icon is the icon on your form.

David
 
Just what I was looking for!

Thanks so much DCrake :)
 
I'm back!

We have decided to make a little change when it comes to giving names to the pdf-files.
Instead of just naming the files after the autoID that is assigned to the different chemicals in the database, we also want the actual name of the chemical in the filename.
The format would then be AutoID#Chemicalname.pdf.

How do I get this code to return the value in front of the separator #?

Code:
Private Sub pdfico_Click()
 
FollowHyperlink "C:\Chemicals\pdf\" & Me.ChemID & ".pdf"
 
End Sub

Thanks!
 
Hi guys,

Could someone please point me in the right direction on my last post please?

Thanks!
 
Code:
Private Sub pdfico_Click()
Dim strFile As String
Dim strPath As String

StrFile = Me.ChemID & Me.ChemName & ".pdf"
StrPath = "C:\Chemicals\pdf\"

If Dir(StrPath & StrFile) <> "" Then
     FollowHyperlink StrPath & StrFile
End If

 
End Sub

Where Me.ChemName is the name of the control on your form that displays the chemical name.

David
 
DCrake,

The challenge here is that the chemical name in the database will sometimes be different from the filename. That is why the code should only pay attention to the number before the separator #.

Autonumber#Chemicalname.pdf

Is this possible?
 
Then I suggest you use the InStr() to check the placement of the # character and read in the preceeding characters. But if you are changing naming conventions why would there be a difference in the chemical names? are you talking about brand names and chemical names. If this is consistant then in your chemicals table you need a field to capture the name that will be used in the file naming convention as an alternative variation on a file name.

David
 

Users who are viewing this thread

Back
Top Bottom