L
Lester Lane
This is very odd. The first time through is fine. If I leave
Word running then the next run is good too. If I close Word then the
next one fails on calling the dialog for new files. 462 Error. If I
open Word first manually I still get the error. Any ideas? Code
below... Sometimes it will run again - maybe after a compile or
something. Am trying to find out what will trigger it. Thanks
Dim objWordApp As Object
Dim rsLetterData As DAO.Recordset
Dim qdfLetterData As DAO.QueryDef
Dim strTemplate As String
Dim i As Integer
Dim intLength As Integer
Dim WaitFor As Single
Dim Start As Single
On Error GoTo ErrTrap
Set qdfLetterData = db.QueryDefs("rsqryLetterData")
qdfLetterData![FacilityID] = FacilityID
Set rsLetterData = qdfLetterData.OpenRecordset
With rsLetterData
If Not .EOF Then
'Is an instance of Word already open that we can bind to?
On Error Resume Next
Set objWordApp = GetObject(, "Word.Application")
On Error GoTo ErrTrap
If objWordApp Is Nothing Then
'Word isn't already running - create a new instance...
Set objWordApp = CreateObject("Word.Application")
objWordApp.Visible = True
Else
End If
objWordApp.Activate
With Dialogs(wdDialogFileNew)
If .Display = -1 Then 'clicked ok
strTemplate = .Template
Else
MsgBox "No Template chosen", vbCritical, "No Template"
Exit Function
End If
End With
......
Word running then the next run is good too. If I close Word then the
next one fails on calling the dialog for new files. 462 Error. If I
open Word first manually I still get the error. Any ideas? Code
below... Sometimes it will run again - maybe after a compile or
something. Am trying to find out what will trigger it. Thanks
Dim objWordApp As Object
Dim rsLetterData As DAO.Recordset
Dim qdfLetterData As DAO.QueryDef
Dim strTemplate As String
Dim i As Integer
Dim intLength As Integer
Dim WaitFor As Single
Dim Start As Single
On Error GoTo ErrTrap
Set qdfLetterData = db.QueryDefs("rsqryLetterData")
qdfLetterData![FacilityID] = FacilityID
Set rsLetterData = qdfLetterData.OpenRecordset
With rsLetterData
If Not .EOF Then
'Is an instance of Word already open that we can bind to?
On Error Resume Next
Set objWordApp = GetObject(, "Word.Application")
On Error GoTo ErrTrap
If objWordApp Is Nothing Then
'Word isn't already running - create a new instance...
Set objWordApp = CreateObject("Word.Application")
objWordApp.Visible = True
Else
End If
objWordApp.Activate
With Dialogs(wdDialogFileNew)
If .Display = -1 Then 'clicked ok
strTemplate = .Template
Else
MsgBox "No Template chosen", vbCritical, "No Template"
Exit Function
End If
End With
......