Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Losing Mail Merge Fields when Sending 2nd file

Status
Not open for further replies.

rccoates

Programmer
Nov 8, 2001
8
US
I have a VB application that emails orders. Each time a new order is placed a word document is built and sent to Outlook to be emailed. Word is then closed. This process works for the first document but on trying to send a second document I come up with the error# 4605 "This method or property is not available because the current mail merge main document has no merge fields."

I use the following code to open a new document.

Dim Retry as boolean

On error goto AppErr

Retry = false

set wrdApp = getobject(,"Word.Application.9")

if Retry = True the
set wrdApp= new Word.Application
end if

set wrdDoc = wrdApp.Documents.Open _(Filename:="c:\Champion\Email.doc")

wrdDoc.MailMerge.MainDocumentType = wdFormLetters
wrdDoc.MailMerge.OpenDataSource Name:="c:\Champion\EmailFax.mdb", _
LinkToSource:= True, Format:=wdOpenFormatAuto, Connection:= "Query qryOrder", SQLStatement:="Select * from [qryOrder]


I build the complete document in vba. The mailmerge fields are added with the following code

with wrdDoc.MailMerge.Fields
.add Range:=Selection.Range, Name:="VCON"
end with

It doesn't process when it passes through this code

I would appreciate any input
RCCoates

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top