Hyperlink to Word Documents

jboyle

New member
Local time
Today, 21:22
Joined
Nov 18, 2000
Messages
53
I have a form that displays a text box that contains the Word document name for the given record being shown. I would like to have a button to hyperlink to the given document.
 
Paste this into a module

Sub OpenWordDoc(strDocName As String)
Dim objApp As Object

'Open document
Set objApp = CreateObject("Word.Application")
objApp.Visible = True
objApp.Documents.Open strDocName
End Sub

On the on_Click event of the button,

Public Sub YourButton_OnClick()
Call OpenWordDoc(me.textboxname)
End Sub

This will call the open doc module and open the respective document. There is no error handling here so if the document does not exist, nothing will open - I suggest you add some error trapping eg filter for null values etc.

HTH
 
Thanks Fizzio, That works GREAT!!!! I did need to type in the path for the file. Is there a way to have the path included?
Example C:\Processes\Motor Assembly.Doc
 
A few ways do do this
either
a) include the full path in the textbox
b) hardcode the path into the code eg.
objApp.Documents.Open "C:\Processes\" & strDocName

c) find the dynamic path eg Docs Folder in the root of your Db

'Extract Database Path for documents - this example gets path of table - tblDocumentList in my case in the BE database
Set MyDb = CurrentDb
strDbPath = MyDb.TableDefs("tblDocumentList").Connect
strDbFile = Dir(Mid(strDbPath, 11, Len(strDbPath)))
strDocPath = Mid(Left(strDbPath, InStr(strDbPath, strDbFile) - 1), 11, Len(strDbPath)) & "Docs\"

or to get the currentDB path

Dim MyDb As DAO.Database, strDbPath As String, intCharacter As Integer

Set MyDb = CurrentDb

strDbPath = MyDb.Name
intCharacter = InStrRev(strDbPath, "\")
strDbPath = Left(strDbPath, intCharacter)


HTH
 

Users who are viewing this thread

Back
Top Bottom