Custom hyperlink form

DBL

Registered User.
Local time
Today, 14:40
Joined
Feb 20, 2002
Messages
659
I have a little pop-up form that shows a list of documents with hyperlinks to the files, filtered to the current record. I switch off the shortcut menus etc so wanted a different way to browse for and get the path to the documents. The form I'm using (thanks Jack) has the following code attached to the browse button:

Private Const EXISTINGFILE As String = "D:\My Documents\My Pictures\*.jpg"
Private Const EXISTINGDIR As String = "D:\MyDocuments\"

Private Sub Command1_Click()
Dim strNewFile As String

On Error GoTo Browse_Err
With Me.cdlgOpen
'You should only use one of the next two lines if you want to open to either a default file or folder
.FileName = EXISTINGFILE 'Comment out if you don't want to open to a default file
'.initdir = ESIXTINGDIR 'Comment out if you don't want to open to a default folder
.CancelError = True
.Filter = "All Files (*.jpg)|*.jpg|" 'Can change (i.e. "Word Files (*.doc)|*.doc|") or ("All Files (*.*)|*.*|") see help for other examples
.ShowOpen ' Can use showSave for saving file, same principle
'strNewFile = .FileName
Me.Image6.Picture = .FileName
Me.Text4 = .FileName
End With

Unfortunately what happens is that when it picks up the file path it stores it in the field as text, regardless of the fact that it's data type in the table is hyperlink. When you click on the file path nothing happens. So, what I need is something so that when I click on the file path in the text/hyperlink field it opens the appropriate document, image etc. We can get it open through a second command button but I want something neater if possible. I'd like to double click the field to get the file path and click to open the file.

Any ideas?

Thanks
 
I did a little looking around, and if in design view of the form, you choose InsertHyperlink (you can fill in the path or leave it blank, but uncheck the relative path checkbox). This will insert a hyperlink label on your form.
[Excerpt from help file]
When you create a label this way, Microsoft Access sets the HyperlinkAddress property of the label to the value you specified in the Link To File Or URL box, and the HyperlinkSubAddress property to the value (if any) you specified in the Named Location In File box. Microsoft Access uses the Caption property for the display text that you see in the label itself. You can change any of these properties to modify the hyperlink.
[End excerpt]

It seem as if you can change the HyperlinkAddress property based on which file was selected by the procedure you outlined.
Change your procedure to
Me.HyperlinkLabelName.HyperlinkAddress = .FileName



The label also has a click and dblclick event you can use to select the file. Hope this helps. For more info in Access help, look up:
Create a label using the Insert Hyperlink button
 
Last edited:
Thanks Charity. I've not managed to resolve this. The only way I can get it to work is by having a Browse button and an Open button but on a continuious form you can imagine how that works. I specifially want to use the custom browse form because it lets me specify the file types and the start folder. Why it saves the hyperlink as a text field I don't know.
 
TADA!!!

Me.txtFile = "#" & .FileName & "#"

A hyperlink address can have up to three parts separated by the pound sign (#):
displaytext#address#subaddress

When you've been assigning the filename to the textbox, it has been interpreted as the display text. Adding the # sign around the filename lets the hyperlink field know that the file name is the address.
 
Charity - you're an absolute marvel. Well done and thank you very much indeed - I'm one happy girl.

Dawn
 

Users who are viewing this thread

Back
Top Bottom