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

how do i follow a hyperlink to a document in vba? 2

Status
Not open for further replies.

AppStaff

Programmer
Sep 21, 2002
146
US
I have an application that will be storing documents names files paths in relation to projects numbers. Where I am having an issue is trying to use that path as a hyperlink in code. How do i tell access to open a file based on a path? Keep in mind that these files are in a variety of formats (word, excel, etc.).

How do I do something like this

dim strLink as string

' set variable equal to a path
strLink= MyPathandfile

'Open file based on path and file name
open strLink



 
if your strlink = say "C:\blah\Myfile.Xls" or Doc or what not, you can use (and I love how simple this is)

followhyperlink strlink

Chaz

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.

 
Thanks for the post. I have been trying to do the same thing but with a twist.

I want the user to input the path to the folder of where the file is... i.e. txtlocation = C:\Documents and Settings\DBA\My Documents\ and in another field input the file name... i.e. txtpicture = 039.jpg

How do I get that exact file to open via hyperlink? Do both fields need to be hyperlink fields? What is the coding for VBA?

Thanks so much!!!

BakerUSMC

 
Hi. With the followhyperlink statement, the argument is a string, so the field does not have to be a hyperlink.

So if you have a path in txtlocation, and a file in txtpicture then

followhyperlink (txtlocation & txtpicture) will open your jpg file.

ChaZ



There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.

 
ChaZ,

Thanks for the quick reply. But when I put my mouseover the txtpicture statement in VBA, the control tip states txtpicture = "(none)" but there is a file name in that field for that record.

So when I click on the command button to view the file, I get a runtime error stating that I can not view that specified file. Please help!!!

BakerUSMC
 
Hi. Can you post your code?

I had assumed txtpicture was a variable you assigned previousley in your code. Is it a field on your form?

If so, maybe me!txtpicture instead of txtpicture. Either way, post the code and let's take a quick glance.

Chaz

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.

 
ChaZ,

That worked!!! Thanks so much. My headache is now gone!!!

BakerUSMC
 
Thanks Blorf star awarded. I'm having another hyperlink issue posted in ms office forum. Perhaps if you get a chance you can give that a go also.
 
Hi. There was a post in Access threads recently, say about 2 months ago with this same problem. I can't seem to find the solution, but it was I think either PHV or Dhookom that gave the answer. I would post your question in access - other topics.

ChaZ

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.

 
Can we expand a little on this topic? I'm trying to do something similar to this. I have pictures on a network that realate to specific jobs. I'm trying to come up with a way to let the user associate the picture to the job in access so I don't have to link all of there pictures. In one field they will insert(this shows as a hyperlink on the form) the picture into a word document and in another field they insert just the picture itself. There are places where the user may want to view just the picture and if that's what they are looking for they can then click the hyperlink to open the word doc to see the verbage that goes along with the pic. Any thoughts or ideas on a way to do this? Any help would be greatly appreciated. :)
 
Well, the word doc, and the picture can both be opend the same way.

Followhyperlink "blah.doc" will launch word with the document (Or the default applicationf for a .doc file)

Same with "Blah.jpg"

ChaZ

There Are 10 Types Of People In The world:
Those That Understand BINARY And Those That Don’t.

 
Hey Chaz! Thanks for responding. I've managed to figure out how to open specific files as you suggested. I have one more challenge. In my table I have a field defined as a hyperlink. I'm trying to let the user store a hyperlinked file of there choice to each record. This kinda works but the data they input ends up being the displayed text and not the hyperlink itself.


On my form I have a text box called txtfile(unbound) and txtViewPicWord (this bound to my hyperlink field in the table). The user types the file name they want to link in the txtfile box and in the onclick event of the txtViewPicWord I complete the path with the file name and store it to the table. Confusing??? I am LOL...here is the code so far.

Code:
Private Sub ViewPicWord_Click()
Dim Response As Integer
Path = "G:\Wireless\Lean Projects\Moonshine Shop\PICs\" & Me!txtFile
Response = MsgBox("Are you ready to link a word document to this Job?", vbQuestion + vbOKCancel, "Link File")
If Response = vbCancel Then Exit Sub

Me!ViewPicWord = (Path)

End Sub
Any ideas on how to make this work?
 
You may take a look at the HyperlinkPart method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hey PHV. I was able to complete my task. Your suggestion helped a lot and got me going in the right direction. Here is how I did it:

Code:
Private Sub ViewPicWord_Click()
Dim Response As Integer
Dim HypPathDoc As String

HypPathDoc = "View Job Specs#G:\Wireless\Lean Projects\Moonshine Shop\PICs\" & Me!txtFile & ".doc#"
Response = MsgBox("Are you ready to link a word document to this Job?", vbQuestion + vbOKCancel, "Link File")
If Response = vbCancel Then Exit Sub

Me!ViewPicWord = HypPath

End Sub

I found the the syntax for the HypPathDoc string in a previously posted thread as I was searching the forum for info on this topic.


Thread 702-697273
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top