I'm outputting several report from Access >> Word but find my client reporting
that the template I insert them into is not closing but reporting locking.
So I've devised this code but find it usually only quits one instance of Word
at a time unless I step through the code when it closes all.
(I judge this using windows task manager and look for Processes = WINWORD.EXE)
Can anyone advise whats wrong here or another way of closing all Word.Applications ??
Public Function fgetwordandquit() As String
'test for open word apps and closes them
On Error Resume Next
Dim myword As Word.Application, wordisrunning As Boolean, C As Byte
wordisrunning = -1
'closes all word applications that are running
Do While wordisrunning = -1
'tests to see if any word application is open
Set myword = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'cannot get application object so err 429
Err.Clear 'Clear Err object
wordisrunning = 0 'all closed so will now quit loop
End If
If wordisrunning = -1 Then
myword.Application.Quit
C = C + 1
End If
Set myword = Nothing
Loop
'MsgBox C
Exit_getthisdoc:
Exit Function
End Function
that the template I insert them into is not closing but reporting locking.
So I've devised this code but find it usually only quits one instance of Word
at a time unless I step through the code when it closes all.
(I judge this using windows task manager and look for Processes = WINWORD.EXE)
Can anyone advise whats wrong here or another way of closing all Word.Applications ??
Public Function fgetwordandquit() As String
'test for open word apps and closes them
On Error Resume Next
Dim myword As Word.Application, wordisrunning As Boolean, C As Byte
wordisrunning = -1
'closes all word applications that are running
Do While wordisrunning = -1
'tests to see if any word application is open
Set myword = GetObject(, "Word.Application")
If Err.Number <> 0 Then 'cannot get application object so err 429
Err.Clear 'Clear Err object
wordisrunning = 0 'all closed so will now quit loop
End If
If wordisrunning = -1 Then
myword.Application.Quit
C = C + 1
End If
Set myword = Nothing
Loop
'MsgBox C
Exit_getthisdoc:
Exit Function
End Function