Opening files from a form

Rasken

New member
Local time
Today, 14:14
Joined
Apr 16, 2013
Messages
6
OK, I have spent the last 10 hours searching for a solution to this and after trying 2 dozen things, I am coming here for the experts advice...

I have a very simple table of basically a unique number and a couple data fields. On my form with those same fields, I need to be able to create a button that opens a pdf file that is named the same as that unique number. Here is the kicker...I have been able to create a hyperlink with a link to that file and it works fine...the problem is that I am making this db for someone else. I am trying to set it up so that the file name is automatically put into the hyperlink statement according to what the unique number is for each record.

what I did so far...

in my hyperlink: *file://c:/docubase/3840.pdf (only put * in so not a link here)

this works fine but I need the syntac to make that line take into account the account field (ID) for each record. So something similar to this (already tried this and it doesnt work)

*file://c:/docubase/[id].pdf

Please help!!!
 
I tried your suggestion and got the following result:

Unable to open *file://c:/docubase/"&[id]&".pdf Cannot open the specified file.

(again only put * here to make it so wasnt posting a link)
 
Could you show the code where you put in the hyperlink in the table, because it is not done the way I expected, then the value of [id] is not inserted.
 
its actually in a form not a table. I created a label and put your code under the hyperlink address in the format section of the label properties. Both my table and the corresponding form have a field called [id]. The link i put on my form works fine if i put an actual file name in. Its just getting the darn thing to work as a result of what ID is. I tried setting it up this way because I am trying to make it as simple as possible for the user. They will be typing in some data then scanning a pdf file that I want to link to each individual record. All they have to do is scan it in and make sure they name it the same as ID and save it in the proper folder (docubase).
 
I created a label and put your code under the hyperlink address in the format section of the label properties.
Okay - on this way you can't get it to work. :)
Either set the example code I've made under the form's current event if ID no already is entered, or under the [ID] control's AfterUpdate event. (Remember to change the label-name to yours)

Code:
Private Sub Form_Current()
  Me.HyperLinkLabel.Caption = "*file://c:/docubase/" & Me.[ID] & ".pdf"
  Me.HyperLinkLabel.HyperlinkAddress = "*file://c:/docubase/" & Me.[ID] & ".pdf"
End Sub
 
I have a very simple table of basically a unique number and a couple data fields. On my form with those same fields, I need to be able to create a button that opens a pdf file that is named the same as that unique number.
So what happens if you use..
Code:
Private Sub theButtonName_Click()
     Application.FollowHyperlink "C:\docubase\" & Me.[ID] & ".pdf"
End Sub
You can make the code a bit robust, by adding a condition to check if a File exists, before using the Follow Hyperlink, adding a good error handler routine etc. but, the above will open a PDF File..
 
Sorry for my lack of knowledge here...but when I put:

Application.FollowHyperlink "C:\docubase\" & Me.[ID] & ".pdf"

into the "on click" property of a button, I get the following message...

"Cannot find the object 'application'
If 'application' is a new macro or macro group, make sure that you have saved it and typed its name correctly"

???????
 
Okay - on this way you can't get it to work. :)
Either set the example code I've made under the form's current event if ID no already is entered, or under the [ID] control's AfterUpdate event. (Remember to change the label-name to yours)

Code:
Private Sub Form_Current()
  Me.HyperLinkLabel.Caption = "*file://c:/docubase/" & Me.[ID] & ".pdf"
  Me.HyperLinkLabel.HyperlinkAddress = "*file://c:/docubase/" & Me.[ID] & ".pdf"
End Sub

OK, JHB, Im thinking your onto something here....but due to my lack of knowledge here....Where do I put that code? And can you explain to me your thinking so I understand what the code is doing? Sorry for my ignorance!
 
FollowHyperlink("c:\docubase\" & [ID] & ".pdf")

Worked! Thanks for all your input!
 
I am trying to do something very similar, but would like to be able to add more than one scanned document. If it is possible, I would like to have a command something like "Attach file" on the form. The user could browse to find the scanned document and it becomes a link. The user could then scan another document, which becomes a second link, in some kind of list box. Do you think it might work?
 
It can work.. Look up on "File Dialog", I am not at my system, so would not be able ti give you sample code.. but you need some bit of coding, with file dialog, and For Loop to achieve this..
 

Users who are viewing this thread

Back
Top Bottom