After overcoming my previous difficulties, I now have another one to contend with. My routine uses three queries to get data from the data base before maimerging the info to print out in word. When step through the application all works fine, however, when I leave the module to its own devices a problem occurs. The first letter prints off without trouble, however between printing the second and third letters word seems to hang for a bit before the Access Logon prompt appears. OK-ing the logon prompt continues the application without any further problems.
Also, if I surround the word app "CreateObject" line with message box objects e.g.
MsgBox "Start of letter no " & LetterNo & " create word app"
Set objWord = CreateObject("word.application")
MsgBox "End of letter no " & LetterNo & " create word app"
the routine works OK allbeit that I have some message boxes to respond to
Any suggestions?
code as follows:
Public Sub PrintReminders(LetterNo As Integer)
Dim objWordDoc As Word.Document
Dim objWord As Word.Application
Dim strFilePath As String
Select Case LetterNo
Case 1
strFilePath = "C:\Documents and Settings\sbny3190\My Documents\A Licences\MailTest1.doc"
strQuery = "qry_Reminder1"
Case 2
strFilePath = "C:\Documents and Settings\sbny3190\My Documents\A Licences\MailTest2.doc"
strQuery = "qry_Reminder2"
Case 3
strFilePath = "C:\Documents and Settings\sbny3190\My Documents\A Licences\MailTest3.doc"
strQuery = "qry_Reminder3"
End Select
On Error GoTo Err_cmd_Reminders_Click
If CheckRecordCount Then
DoCmd.SetWarnings False
Set objWord = CreateObject("word.application")
Set objWordDoc = objWord.Documents.Open(strFilePath)
objWord.ActiveDocument.MailMerge.Execute
With objWord.Application
.DisplayAlerts = wdAlertsNone
.Visible = True
.Options.PrintBackground = False
With .ActiveDocument
.PrintOut
.Close wdDoNotSaveChanges
End With
End With
DoCmd.SetWarnings True
UpdateCorrespondence (LetterNo)
Exit_cmd_Reminders_Click:
objWord.Application.Quit wdDoNotSaveChanges
End If
Set objWordDoc = Nothing
Set objWord = Nothing
Exit Sub
Err_cmd_Reminders_Click:
MsgBox Err.Description
Resume Exit_cmd_Reminders_Click
End Sub
Called from a command button:-
Private Sub cmd_Reminders_Click()
On Error GoTo ErrorHandler
'Print letters in reverse order so that updates can be applied
PrintLetters.PrintReminders (3)
PrintLetters.PrintReminders (2)
PrintLetters.PrintReminders (1)
MsgBox "Reminder letters have been printed", vbInformation + vbOKOnly
ErrorExit:
Exit Sub
ErrorHandler:
Err.Number = Err.Number + 1000
MsgBox Err.Description
Resume ErrorExit
End Sub