Public Function CreateLetters()
' Open a letter in Word and insert text - used by menu command.
'You must put Word in the DAO Reference Library.
Dim Dbs As Database, rstTEMPOwnersMerge As Recordset
Dim appWord As Word.Application
Dim intPages As Integer, StrMessage, I As String
Dim rstSourceTable As String
Dim Worddoc As String
Dim Resp As Integer
Dim Resp2 As Integer
'Make declarations of Source and MergeFiles
rstSourceTable = "TempOwnersMerge"
Worddoc = "C:\AAA My Documents\AISolutions\Products\Y2K9 Conrol\Y2K9 Product\Letters\dog warden questionnaire - stray.dot"
Resp = MsgBox("This procedure can take up considerable system resources." & Chr(13) & _
"To ensure adequate resources are available close down all non-essential programs" & _
" including Word." & Chr(13) & _
"Do you want to cancel this procedure to close some programs?", vbYesNo, "READ ME")
' Open a recordset based on the Merge query.
If Resp = vbYes Then
Exit Function
Else
'Run the Query to Create the Temporary Table
DoCmd.SetWarnings False
DoCmd.OpenQuery ("MergewithChargedOwners"), acViewNormal, acReadOnly
DoCmd.SetWarnings True
Set Dbs = CurrentDb()
Set rstTEMPOwnersMerge = Dbs.OpenRecordset(rstSourceTable)
' If no one has open issues, display a message and exit.
If rstTEMPOwnersMerge.RecordCount = 0 Then
MsgBox "There are no matching records for your criteria, please try again", 0, "No Records"
Exit Function
End If
'Switch to Microsoft Word so it won't go away when you finish.
On Error Resume Next
AppActivate "Microsoft Word"
'If Word isn't running, start and activate it
If Err Then
Shell "c:\Program Files\Microsoft Office\Office\" _
& "Winword /Automation", vbMaximizedFocus
AppActivate "Microsoft Word"
End If
On Error GoTo 0
'Get an Application object so you can automate Word.
Set appWord = GetObject(, "Word.Application")
'Open a document based on the memo template, turn off the
'spell check
With appWord
.Documents.Add Worddoc
.ActiveDocument.ShowSpellingErrors = False
End With
MsgBox "The letter is now on screen and is ready for final editing and merging", 0, "Letter Ready..."
End If
Set Dbs = Nothing
Set rstTEMPOwnersMerge = Nothing
Set appWord = Nothing
Set StrMessage = Nothing
End Function