K
Kenny G
1. Below is my code to print a Word document. The data for the Word
document comes from a table under the subform sfrmReports. Sfrm reports is a
subform of frmReports. Should the frm or sfrm be referenced in my code?
Currently I have the frm.
2. I am getting the following error message "Word cannot save this file
because it is already open elsewhere."
Sub PrintTracerSurveyReport(tblNonCompIPOPAllStandards)
Dim objWord As Word.Application
Dim objDoc As Word.Document
'Launch Word and load the JCAHOTracerPreSurveyReport template
Set objWord = New Word.Application
objWord.Visible = False
Set objDoc = objWord.Documents.Add("S:\Quality & Process
Improvement\QPI\JCAHO PreSurvey Tool\Documents\JCAHOPreSurveyReport.dot")
'Add information using predefined bookmarks
With objDoc.Bookmarks
.Item("DirectorCoordinator").Range.Text =
frmReports.DirectorCoordinator
.Item("SurveyID").Range.Text = frmReports.SurveyID
.Item("SurveyDate").Range.Text = frmReports.SurveyDate
.Item("SubSiteName").Range.Text = frmReports.SubSiteName
.Item("Standard").Range.Text = frmReports.Standard
.Item("Observation").Range.Text = frmReports.Observation
.Item("Recommendation").Range.Text = frmReports.Recommendation
.Item("FollowupComments").Range.Text = frmReports.FollowupComments
End With
objWord.PrintOut
objDoc.Close wdDoNotSaveChanges
objWord.Quit
End Sub
Any help would be appreciated.
document comes from a table under the subform sfrmReports. Sfrm reports is a
subform of frmReports. Should the frm or sfrm be referenced in my code?
Currently I have the frm.
2. I am getting the following error message "Word cannot save this file
because it is already open elsewhere."
Sub PrintTracerSurveyReport(tblNonCompIPOPAllStandards)
Dim objWord As Word.Application
Dim objDoc As Word.Document
'Launch Word and load the JCAHOTracerPreSurveyReport template
Set objWord = New Word.Application
objWord.Visible = False
Set objDoc = objWord.Documents.Add("S:\Quality & Process
Improvement\QPI\JCAHO PreSurvey Tool\Documents\JCAHOPreSurveyReport.dot")
'Add information using predefined bookmarks
With objDoc.Bookmarks
.Item("DirectorCoordinator").Range.Text =
frmReports.DirectorCoordinator
.Item("SurveyID").Range.Text = frmReports.SurveyID
.Item("SurveyDate").Range.Text = frmReports.SurveyDate
.Item("SubSiteName").Range.Text = frmReports.SubSiteName
.Item("Standard").Range.Text = frmReports.Standard
.Item("Observation").Range.Text = frmReports.Observation
.Item("Recommendation").Range.Text = frmReports.Recommendation
.Item("FollowupComments").Range.Text = frmReports.FollowupComments
End With
objWord.PrintOut
objDoc.Close wdDoNotSaveChanges
objWord.Quit
End Sub
Any help would be appreciated.