Opening word-document

  • Thread starter Thread starter Lodewijk Olthof
  • Start date Start date
L

Lodewijk Olthof

In a form there is a field with the path and name of a document. How can I
open that document by clicking a button?
 
Hi Lodewijk,

The simplest way is to use something like this in the button's Click
event procedure, where txtXXX is the name of the textbox on the form:

Application.FollowHyperlink Me.txtXXX.Value
 
The simplest way is to use something like this in the button's Click
event procedure, where txtXXX is the name of the textbox on the form:

Application.FollowHyperlink Me.txtXXX.Value

I assume this only works if the extension of the file is in the txtXXX
Because i get an error

Lodewijk
 
Of course. Without the extension Windows has no way of knowing what
application to use to open the document.

If these are files whose names have no extensions, you will need to
launch the relevant application explicitly, e.g. with something like

Dim oWord as Object
On Error Resume Next
'Get hold of WOrd if it's running
Set oWord = GetObject(,"Word.Application")
If oWord Is Nothing Then
'not running, launch it ourselves
Set oWord = CreateObject("WOrd.Application")
If oWord Is Nothing Then
MsgBox "Couldn't launch Word"
Exit Sub
End If
End If
oWord.Visible = True
oWord.Documents.Open Me.txtXXX.Value & "."

Or if they have extensions but these are not stored in the database,
just add the right extension.

Application.FollowHyperlink Me.txtXXX.Value & ".DOC"
 
Back
Top