Opening word-document

  • Thread starter Lodewijk Olthof
  • 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?
 
J

John Nurick

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
 
L

Lodewijk Olthof

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
 
J

John Nurick

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"
 

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