Connecting Tech Pros Worldwide Forums | Help | Site Map

mail merge to word

Aaron
Guest
 
Posts: n/a
#1: Nov 13 '05
hello,

i am perfoming a mail merge with the following code.

Public Function MergeIt()
Dim objWord As Object
Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
' Make Word visible.
objWord.Application.Visible = True
' Set the mail merge data source as the db3 database.
objWord.MailMerge.OpenDataSource _
Name:="C:\Rapid Motion\Client " & _
"Info\Accident Claims UK\db3.mdb", _
LinkToSource:=True, _
Connection:="TABLE tblsolicitordetails", _
SQLStatement:="SELECT * FROM [tblsolicitordetails]"
' Execute the mail merge.
objWord.MailMerge.Execute
End Function

the first time i execute it, it fails because the word document does
not have the merge fields in place.

So i open the word document myMerge then set up the merge fields and
save it.

the second time i open it 2 instances of Word open, 1 with my merged
fields and all the merge options, and another that simply shows the
values of the merged fields and no merge options.

Why does this happen?

Aaron

Mal Reeve
Guest
 
Posts: n/a
#2: Nov 13 '05

re: mail merge to word



"Aaron" <aaron@rapid-motion.co.uk> wrote in message
news:260d7f40.0408011240.654a5cdc@posting.google.c om...[color=blue]
> hello,
>
> i am perfoming a mail merge with the following code.
>
> Public Function MergeIt()
> Dim objWord As Object
> Set objWord = GetObject("C:\MyMerge.doc", "Word.Document")
> ' Make Word visible.
> objWord.Application.Visible = True
> ' Set the mail merge data source as the db3 database.
> objWord.MailMerge.OpenDataSource _
> Name:="C:\Rapid Motion\Client " & _
> "Info\Accident Claims UK\db3.mdb", _
> LinkToSource:=True, _
> Connection:="TABLE tblsolicitordetails", _
> SQLStatement:="SELECT * FROM [tblsolicitordetails]"
> ' Execute the mail merge.
> objWord.MailMerge.Execute
> End Function
>
> the first time i execute it, it fails because the word document does
> not have the merge fields in place.
>
> So i open the word document myMerge then set up the merge fields and
> save it.
>
> the second time i open it 2 instances of Word open, 1 with my merged
> fields and all the merge options, and another that simply shows the
> values of the merged fields and no merge options.
>
> Why does this happen?
>
> Aaron[/color]

Your code includes a[color=blue]
> ' Execute the mail merge.
> objWord.MailMerge.Execute[/color]

so the merge is executed and the output is made..

Where did you want it to go?
I think the default is to 'merge to a new document'
there is probably an argument for the others (printer or email) but having
not experiemented with these I can't help you with what they might be.

Mal.


Albert D. Kallal
Guest
 
Posts: n/a
#3: Nov 13 '05

re: mail merge to word


Hum, I am going to suggest that you give my sample word merge a try. It
should work for you.

You can read the notes on how/why I fixed problems like the 2nd copy of
ms-access being launched, and also issues of security.

no need to re-invent the wheel here. Check out the word merge at:
http://www.attcanada.net/~kallal.msn.../msaccess.html
--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com
http://www.attcanada.net/~kallal.msn


Closed Thread