Opening a Word Document from Access

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to Open a Word Document from an Access form "User Documentation"
I get an Automation Error. I am using Access 2000 for testing. However, it
will be installed using Access 97. Could some one please help:

Private Sub Command0_Click()

Dim objword As Word.Application
Dim objDoc As Word.Document
Dim DocPath As String

DocPath = "c:\MyPath\UserDoc.doc"

Set objword = New Word.Application

'************************************************
' Automation Error - The Server Threw An Exception
' Run Time Error -2147417851
' Note - I have Triple Check the Path, It's Correct
'************************************************
Set objDoc = objword.Documents.Open(DocPath)
'************************************************

objDoc.Activate
objword.Visible = True

End Sub
 
Do you have reference to Microsoft Word 11.0 Object Library?
To check open any code section, or the immidiate window, select tools,
reference.
If you dont have then create by browsing and selecting MSWORD.OLB, probably
under c:\Program Files\Microsoft Office\Office11\

But its better to check by searching for it.
 
If you want it to work with multiple versions, you must use late binding.
Remove the reference to the Word object library and change your code as
follows:
 
Back
Top