BoulderRidge
Programmer
I am pushing data to Word from Access 2003.
This code and subsequent document manipulation all works IF I have Word already open with any document (the 'GetObject'piece works).
If I DON'T have Word open, it drops to the 'CreateObject' code and always fails on this line with Err.Number = -2147024770 which says 'Automation error. The specified module could not be found.'
Here is the code:
Public Function RunAddChangeRpt(datTargetDate As Date, lngEmployeeID As Long, Optional strReportDoc As String = "") As Boolean
RunAddChangeRpt = True
On Error GoTo ErrMe
Dim strFilePathTemplate As String
Dim strFilePathReport As String
Dim strMyReportDoc As String
'Dim objWord As Object
Dim blnCloseAPP As Boolean 'if we open it, then we should close it
Dim APP As Object
Dim Doc As Object
'Dim APP As Word.Application
'Dim Doc As Word.Document
Dim Conn As ADODB.Connection
Dim rsData As ADODB.Recordset
'*******Open Doc***** (Code from multiple Tek-Tips postings combined)
blnCloseAPP = False
On Error Resume Next
Set APP = GetObject(, "word.application")
'declare the error default statement
On Error GoTo ErrMe
If TypeName(APP) = "Nothing" Then
'Word was not open -- create a new instance
Set APP = CreateObject("Word.Application")
If APP Is Nothing Then
'does not have word on their system
MsgBox "The Word application does not exist on this system!", vbCritical, "ERROR"
GoTo ErrMe 'the exit routine
End If
blnCloseAPP = True
End If
APP.Visible = True 'use false to hide your app in the background, and true to display it.
...continue from here to manipulate document....
My references are set like this:
- Visual Basic for Applications
- Microsoft Access 11.0 Object Library
- Microsoft Word 11.0 Object Library
- OLE Automation
- Microsoft ActiveX Data Objects 2.8 Library
- Microsoft ADO Ext. 2.8 for DDL and Security
- Microsoft DAO 3.6 Object Library
Why would GetObject work but CreateObject fail in the same environment???
Any clues would be much appreciated. Trying to wrap this up today. Thanks!
-- BoulderRidge
This code and subsequent document manipulation all works IF I have Word already open with any document (the 'GetObject'piece works).
If I DON'T have Word open, it drops to the 'CreateObject' code and always fails on this line with Err.Number = -2147024770 which says 'Automation error. The specified module could not be found.'
Here is the code:
Public Function RunAddChangeRpt(datTargetDate As Date, lngEmployeeID As Long, Optional strReportDoc As String = "") As Boolean
RunAddChangeRpt = True
On Error GoTo ErrMe
Dim strFilePathTemplate As String
Dim strFilePathReport As String
Dim strMyReportDoc As String
'Dim objWord As Object
Dim blnCloseAPP As Boolean 'if we open it, then we should close it
Dim APP As Object
Dim Doc As Object
'Dim APP As Word.Application
'Dim Doc As Word.Document
Dim Conn As ADODB.Connection
Dim rsData As ADODB.Recordset
'*******Open Doc***** (Code from multiple Tek-Tips postings combined)
blnCloseAPP = False
On Error Resume Next
Set APP = GetObject(, "word.application")
'declare the error default statement
On Error GoTo ErrMe
If TypeName(APP) = "Nothing" Then
'Word was not open -- create a new instance
Set APP = CreateObject("Word.Application")
If APP Is Nothing Then
'does not have word on their system
MsgBox "The Word application does not exist on this system!", vbCritical, "ERROR"
GoTo ErrMe 'the exit routine
End If
blnCloseAPP = True
End If
APP.Visible = True 'use false to hide your app in the background, and true to display it.
...continue from here to manipulate document....
My references are set like this:
- Visual Basic for Applications
- Microsoft Access 11.0 Object Library
- Microsoft Word 11.0 Object Library
- OLE Automation
- Microsoft ActiveX Data Objects 2.8 Library
- Microsoft ADO Ext. 2.8 for DDL and Security
- Microsoft DAO 3.6 Object Library
Why would GetObject work but CreateObject fail in the same environment???
Any clues would be much appreciated. Trying to wrap this up today. Thanks!
-- BoulderRidge