[AccessD] Problem with Word Automation

A.D.TEJPAL adtp at hotmail.com
Wed May 9 14:05:50 CDT 2007


Susan,

    Sample subroutine as given below, on being tested at my end, is found to work smoothly.

Best wishes,
A.D.Tejpal
---------------

Sample subroutine
===============================
Sub P_GetWordDoc()
    On Error GoTo ErrTrap
    Dim appWord As Word.Application
    Dim doc As Word.Document
    Dim DocPath1 As String, DocPath2 As String
    
    DocPath1 = "C:\TEMP\Test 01.doc"
    DocPath2 = "C:\TEMP\Test 02.doc"
    
    On Error Resume Next
    Err.Clear
    Set appWord = GetObject(, "Word.Application")
    If Err.Number <> 0 Then
        Set appWord = New Word.Application
    End If
    On Error GoTo ErrTrap
  
    Set doc = appWord.Documents.Open(DocPath1, , True)
    
    On Error Resume Next
    Kill DocPath2
    doc.SaveAs DocPath2

ExitPoint:
    On Error Resume Next
    doc.Close
    appWord.Quit
  
    Set doc = Nothing
    Set appWord = Nothing
    On Error GoTo 0
    Exit Sub
        
ErrTrap:
    MsgBox Err.Number & " - " & _
            Err.Description, vbCritical + vbOKOnly, _
            "Error Encountered"
    Resume ExitPoint
End Sub
===============================

  ----- Original Message ----- 
  From: Susan Harkins 
  To: 'Discussion of Hardware and Software issues' ; AccessD at databaseadvisors.com 
  Sent: Wednesday, May 09, 2007 23:04
  Subject: [AccessD] Problem with Word Automation


    'Print customer slip for current customer.
    Dim appWord As Word.Application
    Dim doc As Word.Document
    'Dim rst As ADODB.Recordset
    'Dim strSQL As String
    
    'Set appWord = GetObject(, "Word.Application")

    Set appWord = New Word.Application
    
    'With appWord
    'Set doc = appWord.Documents("Customer Slip")
    
    On Error GoTo errHandler
    Set doc = appWord.Documents.Open("C:\WordForms\Customer Slip", , True)

  As you can see from the commented lines, I've tried a number of ways to
  retrieve a Word document named Customer Slip -- I want to fill predefined
  fields with Access data. 

  If I tried to set the Documents property to the file name I get a "bad file"
  error. If I try to do it in the .Open method, I get the following: 

  -2147417851 
  Automation error
  The server threw an exception. 

  I don't have a clue what that means. 

  Susan H. 


More information about the AccessD mailing list