"Object Variable or With Block Variable Not Set"

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top