Edit Hyperlink with Code rather than the EditHyperlink Dialog

L

Lara

Hi, I've got a table with several hundred records. One field contains
filenames, an other one contains hyperlinks to each of those files.

Some of the files, (which are templates and can't be changed), will be
selected via tickbox by the user. If the user wants to see the content of
the files before selecting them, he uses the hyperlink field to view them and
then makes up his mind. That's all easy.

Now, by clicking on a button the ticked filenames and hyperlinks get
appended to a new table, and the files get copied into a new folder. The user
wants to access them to apply individual changes.

Now of course the old hyperlink does not point to the newly copied files, so
I used code to change the hyperlink address from:

Folder1\Filename.doc#Folder1/Filename.doc# to
Folder2\Filename.doc#Folder2/Filename.doc#.

In the new table the ammended hyperlink looks just right, (blue underlined,
just like a hyperlink should be looking) but when I click on it to access a
file in the new folder I get the message "unable to open
Folder2/Filename"..... The only way to make it work is to physically go into
the hyperlink and edit it, after which it works of course even though still
looks the same as before.... And of course with several hundred files that's
unacceptable for the user.

I've looked at several articles about editing hyperlinks, but have found
none which uses code to do so.

It also came to me that I could use the shell command to access those files,
but now, after trying for so long, I am real curious if it still could be
done via hyperlink....

Thanks Lara
 
D

Dale Fye

Lara,

I dislike the hyperlink data type and avoid it whenever possible.

I usually make these types of fields text and use the docmd.followhyperlink
method to open the hyperlink either in a double click event in the field or
in a click event of a command button.

HTH
Dale
 
L

Lara

Hi Dale,
this is phantastic! It actually works better than the Shell command because
I don't have to worry about the Program Path which opens a specific file.

However I found that in my version Access 2003 Docmd.FollowHyperlink does
not exist, but Application.FollowHyperlink does the job.

Are you actually able to use DoCmd.FollowHyperlink? If yes, have you
activated a special library or something like it?

Thanks for the help, (I just love these forums!)
 
D

Dale Fye

My bad!

Sorry my suggestion didn't work, glad you were able to figure out what I
meant!
 
L

Lara

It actually helped me not only for the problem I posed the question for, but
gave me ideas for heaps of other places where I can use it. -> Your
suggestion was truly a diamond, especially none of my searches in regards to
hyperlinks had returned FollowHyperlink. Big smile, Lara
 
D

DawnTreader

Hello

could either of you post some code? i would be interested in what you are
doing and how it is done.

i have a "linking" situation that i want to resolve and your code may be my
answer. thanks.
 
D

Dale Fye

Dawn,

Suppose you have a text field in one of your tables that contains filenames,
including the entire path to that file, and you want to be able to open that
file, in whatever application uses it. Now, you could change the fields
data type to a hyperlink field, so that when you click in the textbox it
automatically opens that document. But if you want to be able to change the
text in that field for some reason, this will not work, because the actual
text stored in a hyperlink field is not just the URL.

So there are a couple of ways to deal with this. If you want to test for
the file type, and know where the basic applications reside on your hard
drive, you can use the shell command to open a specific application and pass
it the file name. As an alternative to this, you could do a couple of other
things.

1. You could create a label control on the form, and assign the labels
HyperlinkAddress property the value of the field. If you do this, then when
you click on the label, the application will launch the application that is
mapped to that document type. This would allow you to edit the value in the
textbox, and in the textboxes afterupdate event, set the HyperlinkAddress
property of the label to the value in the text field

Private sub txt_FileName_AfterUpdate

me.lbl_Hyperlink.hyperlinkAddress = me.txt_FileName

End Sub

BTW, You would also need to add a similar statement to the Forms current
event, so that as you move to each record, it sets this property

2. An alternative is that you add a command button to the form, and put
some code in it's click event to follow the hyperlink. With this method,
you don't have to set any properties in the forms current event, or when the
user updates the data in the field. Additionally, the FollowHyperlink
method has several parameters that can be passed to it.

Private sub cmd_FollowHyperlink_Click

application.followhyperlink me.txt_FileName

End Sub

HTH
Dale
 
D

DawnTreader

Hello

i have an even better idea. i dont want to store the links anymore. instead
i would like a button that takes a field and then searches for the folder
within a specific folder that matches that field or portion of that field,
and then pops up an explorer window on the folder. this would allow me to
follow that folder where ever it might be moved to and not have to store
anything other than the one field.

here is the scenario in detail.

we have a folder we call WO on a specific network drive. inside that folder
are categories, Compressor, Dispenser and others. inside the categories there
are folders by the serial number of the particular units. for example
"08242_Airport_ Petrocan_CA" is a typical folder name.

in my app i have a field that stores just the serial number like 08242. what
i want to do is to search on the field to find the folder, then open the
"08242_Airport_ Petrocan_CA" folder at the push of a button. this removes the
need for hyperlink fields and also allows for moving and renaming of the
folder without causing distress in the hyperlink system. the folder gets
moved into another subfolder at one point but if this idea works then it wont
matter where it gets moved to as long as it is within the "WO" folder where
all these units are stored. renaming will never change the serial number
being part of the folder name so that again wont cause this idea any problems.

anyone have suggestions for code that can do this?
 
D

Dale Fye

Dawn,

I have at least one old program where I only store the file name, not the
path. Files were getting moved too frequently, so I just started storing
the name and not the path. If the file is not found in the default path, it
backs up one level, and searches that folder and all of its other
sub-folders, and continues to do so until it finds the file. For later
applications, I generally copied the files to a hiddden folder on my
network, and stored the whole path. With this scenario, I could relatively
guarantee that the file path was not going to change very frequently.

Not a bad idea, but how often are you going to have to perform this search?
If often, I would recommend creating a table to store your WO folder
subfolders and their folders, along with the full UNC path to that folder.
You could fill this table relatively quickly at startup, or the first time
you perform the search, then clean it out at the end of the day (if you
think you need to). This way, the first time you search for a folder each
day, you would develop the complete folder structure. From then on, all you
would have to do is search in that table.

Dale
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top