Public Function PGCertification()
Dim dbs As Database, rstMerge As Recordset
Dim rstFiltered As Recordset
Dim intPages As Integer
Dim AppWord As Word.Application
' Return reference to current database.
Set dbs = CurrentDb
' Create dynaset-type Recordset object.
Set rstMerge = dbs.OpenRecordset("qryMergeDocs", dbOpenDynaset)
' Set filter condition.
rstMerge.Filter = "FacID = '" & strFacID & "'"
' Create filtered dynaset-type Recordset object.
Set rstFiltered = rstMerge.OpenRecordset
On Error Resume Next
'Get an Application object so you can automate Word.
Set AppWord = CreateObject("Word.Application")
With AppWord
.Visible = True
.Documents.Add "T:\Team6Merge\" & strMergeDoc & ".dot"
.ActiveDocument.ShowSpellingErrors = False
.Selection.Goto wdGoToBookmark, Name:="SiteName"
.Selection.TypeText rstFiltered![Site Name]
.Selection.Goto wdGoToBookmark, Name:="SiteAddress"
.Selection.TypeText rstFiltered![Site Address]
.Selection.Goto wdGoToBookmark, Name:="SiteCity"
.Selection.TypeText rstFiltered![Site City]
.Selection.Goto wdGoToBookmark, Name:="SiteCounty"
.Selection.TypeText rstFiltered!County
.Selection.Goto wdGoToBookmark, Name:="FacID"
.Selection.TypeText rstFiltered!FacID
.Selection.Goto wdGoToBookmark, Name:="StaffMember"
.Selection.TypeText rstFiltered!Signature
End With
'Get the number of pages in the memo, ask the user whether to print it, and then tell Word to print it.
intPages = AppWord.Selection.Information(wdNumberOfPagesInDocument)
MsgBox "The document is complete, and has " & CStr(intPages) & " pages." & Chr(13) & "Please review and edit before printing.", vbOKOnly
rstMerge.Close
rstFiltered.Close
dbs.Close
End Function