I have an Access program that supplies information to a Word template that I do not want to save the changes to. I use the template to fill in the blanks then I have to manually insert additional information prior to printing it out. I can open the document I can insert my data but here is where I have trouble ... making the word document basically act like a MODAL form ... keeping focus while I edit the document. Suggestions please. This is the code I use:
sub PrintAControlSheet(docTemplate as String)
'docTemplate = path/filename of the routing sheet template
Dim objWord As Word.Application ' word object
Dim objDoc As Object ' document object
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Select *,[ID Number] AS ID_Number from [Initial Log Entry]WHERE [ID Number] = " & ID & ";", dbOpenDynaset)
Set objWord = CreateObject("Word.Application"
Set objDoc = objWord.Documents.Add(docTemplate)
'InsertTextAtBookmark is a procedure that actually gets used in a loop to fill in the Word document
InsertTextAtBookmark objWord, objDoc, "ID_Number", rs.Fields("ID_Number"
'HERE IS WHERE I WOULD LIKE THE PROGRAM TO WAIT WHILE I MAKE MANUAL EDITS TO THE WORD DOCUMENT
'Finish up with the following
Set rs = Nothing
Set db = Nothing
objDoc.Close wdDoNotSaveChanges
objWord.Quit
Set objDoc = Nothing
Set objWord = Nothing
end sub
Sub InsertTextAtBookmark(objW As Object, objD As Object, strBkmk As String, _
varText As Variant)
' select the required bookmark, and set the selection text
objD.Bookmarks(strBkmk).Select
objW.Selection.Text = varText
' objW.Selection.Text = varText
End Sub
sub PrintAControlSheet(docTemplate as String)
'docTemplate = path/filename of the routing sheet template
Dim objWord As Word.Application ' word object
Dim objDoc As Object ' document object
Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("Select *,[ID Number] AS ID_Number from [Initial Log Entry]WHERE [ID Number] = " & ID & ";", dbOpenDynaset)
Set objWord = CreateObject("Word.Application"
Set objDoc = objWord.Documents.Add(docTemplate)
'InsertTextAtBookmark is a procedure that actually gets used in a loop to fill in the Word document
InsertTextAtBookmark objWord, objDoc, "ID_Number", rs.Fields("ID_Number"
'HERE IS WHERE I WOULD LIKE THE PROGRAM TO WAIT WHILE I MAKE MANUAL EDITS TO THE WORD DOCUMENT
'Finish up with the following
Set rs = Nothing
Set db = Nothing
objDoc.Close wdDoNotSaveChanges
objWord.Quit
Set objDoc = Nothing
Set objWord = Nothing
end sub
Sub InsertTextAtBookmark(objW As Object, objD As Object, strBkmk As String, _
varText As Variant)
' select the required bookmark, and set the selection text
objD.Bookmarks(strBkmk).Select
objW.Selection.Text = varText
' objW.Selection.Text = varText
End Sub