R
Ron
I'm using OLE to transfer data from Access to Word, the
problem I'm having is closing the Word documents, the
user gets a Close prompt for each document created(which
I'm trying to avoid). Can you tell me how to close the
documents in the code? Here is a code sample:
Dim db As Database, cSQL As String, rs As Recordset
Dim objWord As Word.Application
cSQL = "SELECT * FROM tblRespondent ORDER BY Number, Name"
Set db = CurrentDb()
Set rs = db.OpenRecordset(cSQL)
If rs.RecordCount > 0 Then
rs.MoveFirst
While Not rs.EOF
'Launch Word and load template
Set objWord = New Word.Application
objWord.Documents.Add _
Application.CurrentProject.Path & "\CHRONOI.dot"
objWord.Visible = False
With objWord.ActiveDocument.Bookmarks
.Item("Number").Range.Text = rs!Number
.Item("Respondent").Range.Text = rs!Name
objWord.PrintOut
End With
rs.MoveNext
Wend
End If
rs.Close
Set rs = Nothing
problem I'm having is closing the Word documents, the
user gets a Close prompt for each document created(which
I'm trying to avoid). Can you tell me how to close the
documents in the code? Here is a code sample:
Dim db As Database, cSQL As String, rs As Recordset
Dim objWord As Word.Application
cSQL = "SELECT * FROM tblRespondent ORDER BY Number, Name"
Set db = CurrentDb()
Set rs = db.OpenRecordset(cSQL)
If rs.RecordCount > 0 Then
rs.MoveFirst
While Not rs.EOF
'Launch Word and load template
Set objWord = New Word.Application
objWord.Documents.Add _
Application.CurrentProject.Path & "\CHRONOI.dot"
objWord.Visible = False
With objWord.ActiveDocument.Bookmarks
.Item("Number").Range.Text = rs!Number
.Item("Respondent").Range.Text = rs!Name
objWord.PrintOut
End With
rs.MoveNext
Wend
End If
rs.Close
Set rs = Nothing