M
mj
Hi. I have some code that's supposed to be looping through
a recordset and inserting text into a bookmarked Word
document. It seems to be getting hung up on the recordset.
Any thoughts would be great!! Thanks!!
Here's my module:
Option Compare Database
Private Const m_strTEMPLATE As String = " Q2 Sales
Plan.doc"
Private m_objWord As Word.Application
Private m_ObjDoc As Word.Document
Public Sub CreateSalesPlanLetter(recPlan As Recordset,
recPlanRecipients As Recordset)
Dim m_strDIR As String
Set m_objWord = New Word.Application
Set m_ObjDoc = m_objWord.Documents.Add("C:\Documents and
Settings\myname\Desktop\Q2 Sales Plan.doc")
'It is getting hung up here...
InsertTextAtBookmark "AprilOther", recPlanRecipients
("Territory")
m_objWord.PrintOut Background:=False
m_ObjDoc.SaveAs FileName:=m_strDIR & recPlanRecipients
("Territory") & _
" - " & FormatDateTime(Date, vbLongDate) & ".DOC"
m_ObjDoc.Close
m_objWord.Quit
Set m_ObjDoc = Nothing
Set m_objWord = Nothing
End Sub
Private Sub InsertTextAtBookmark(strBkmk As String,
varText As Variant)
m_ObjDoc.Bookmarks(strBkmk).Select
m_objWord.Selection.Text = varText & ""
End Sub
Not sure if you need this, but the on click event that
calls the module is below:
Private Sub SendSalesPlansToTerritoryManagers_Click()
Dim msgresp
Dim recPlan As Recordset
Dim recPlanRecipients As Recordset
msgresp = MsgBox("Send plans?", vbYesNo)
If msgresp = vbYes Then
Set Db = CurrentDb
Set rs = Db.OpenRecordset("SELECT * " & _
"FROM
[qryPlanParticipantsByTerritory] " & _
"WHERE Not [Internet Address] Is Null")
If Not rs.EOF Then
Do While Not rs.EOF
CreateSalesPlanLetter recPlan, recPlanRecipients
rs.MoveNext
Loop
End If
Exit Sub
End If
End Sub
a recordset and inserting text into a bookmarked Word
document. It seems to be getting hung up on the recordset.
Any thoughts would be great!! Thanks!!
Here's my module:
Option Compare Database
Private Const m_strTEMPLATE As String = " Q2 Sales
Plan.doc"
Private m_objWord As Word.Application
Private m_ObjDoc As Word.Document
Public Sub CreateSalesPlanLetter(recPlan As Recordset,
recPlanRecipients As Recordset)
Dim m_strDIR As String
Set m_objWord = New Word.Application
Set m_ObjDoc = m_objWord.Documents.Add("C:\Documents and
Settings\myname\Desktop\Q2 Sales Plan.doc")
'It is getting hung up here...
InsertTextAtBookmark "AprilOther", recPlanRecipients
("Territory")
m_objWord.PrintOut Background:=False
m_ObjDoc.SaveAs FileName:=m_strDIR & recPlanRecipients
("Territory") & _
" - " & FormatDateTime(Date, vbLongDate) & ".DOC"
m_ObjDoc.Close
m_objWord.Quit
Set m_ObjDoc = Nothing
Set m_objWord = Nothing
End Sub
Private Sub InsertTextAtBookmark(strBkmk As String,
varText As Variant)
m_ObjDoc.Bookmarks(strBkmk).Select
m_objWord.Selection.Text = varText & ""
End Sub
Not sure if you need this, but the on click event that
calls the module is below:
Private Sub SendSalesPlansToTerritoryManagers_Click()
Dim msgresp
Dim recPlan As Recordset
Dim recPlanRecipients As Recordset
msgresp = MsgBox("Send plans?", vbYesNo)
If msgresp = vbYes Then
Set Db = CurrentDb
Set rs = Db.OpenRecordset("SELECT * " & _
"FROM
[qryPlanParticipantsByTerritory] " & _
"WHERE Not [Internet Address] Is Null")
If Not rs.EOF Then
Do While Not rs.EOF
CreateSalesPlanLetter recPlan, recPlanRecipients
rs.MoveNext
Loop
End If
Exit Sub
End If
End Sub