get error 5361 in mailmerge automation

S

sparty1022

automating Word 2003 from vb6 program to mailmerge into a letter the
following is my code:

pstrRS1 = "select lname, ssn, address1, city, state, zip, phone from person
where personid = '" & breederid & "'"
Debug.Print pstrRS1

pcon.Open gConnectString
rsPayee.Open pstrRS1, pcon, adOpenForwardOnly, adLockReadOnly, adCmdText


If rsPayee.EOF = True Then
pcon.Close
Set pcon = Nothing
MsgBox "There is no Person record for this Breeder", vbCritical,
"Missing Person record for Breeder"
Exit Sub
Else

'create an instance of word and make it visible
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = False

'What document do I want to open
SetMMPath
Set wrdDoc = wrdApp.Documents.Open(gstrPayeeReg)
wrdDoc.Select
Set wrdSelection = wrdApp.Selection
Set wrdMailMerge = wrdDoc.MailMerge
End If

iRow = 2
wrdDoc.MailMerge.CreateDataSource
Name:="C:\windows\temp\NewPayeeDataDoc.doc", _
headerrecord:="LName, SSN, LName1, Address1, City, State, Zip, Phone"

Set wrdDataDoc =
wrdApp.Documents.Open("C:\windows\temp\NewPayeeDataDoc.doc")


lname = rsPayee!lname
SSN = IIf(Not IsNull(rsPayee!SSN), rsPayee!SSN, "")
Address1 = IIf(Not IsNull(rsPayee!Address1), rsPayee!Address1, "")
city = IIf(Not IsNull(rsPayee!city), rsPayee!city, "")
State = IIf(Not IsNull(rsPayee!State), rsPayee!State, "")
zip = IIf(Not IsNull(rsPayee!zip), rsPayee!zip, "")
If Len(rsPayee!Phone) = 7 Then
Phone = Format(rsPayee!Phone, "###-####")
ElseIf Len(rsPayee!Phone) = 10 Then
Phone = Format(rsPayee!Phone, "(###)###-####")
Else
Phone = ""
End If

FillpayeeReg wrdDataDoc, iRow, lname, SSN, lname, Address1, city, State,
zip, Phone

wrdMailMerge.Destination = wdSendToNewDocument
wrdMailMerge.Execute False <*********Error
occurs here
wrdApp.Options.PrintBackground = False
wrdApp.ActiveDocument.PrintOut
wrdApp.ActiveDocument.Close True

wrdDataDoc.Saved = True
wrdDataDoc.Close True

wrdDoc.ActiveWindow.Close True
wrdApp.Quit

Set wrdSelection = Nothing
Set wrdMailMerge = Nothing
Set wrdMergeFields = Nothing
Set wrdDataDoc = Nothing
Set wrdDoc = Nothing
Set wrdApp = Nothing

'mrstViolations.Close
rsPayee.Close
pcon.Close
Set pcon = Nothing


I had previously used this code in Word2000 without issues what is happening
now?

I based this off the kb 220607 article.
 

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