Help with Mail Merge and word
Sorry but am just getting started with Automation and am finding it a little
tricky, I have gone through the Automation book which has helped but am
now a little stuck: -
I have created a letter and attached a header , if I open the letter up in
word it is all ok and it has the header attached.
My problem is when I run the following code it all opens up and does what
I think it should be doing but it changes the header and inserts the first
row into the header so if the header was "pd_surname" it puts in "pd_surname
smith"
Where am I going wrong?
LOCAL cTemplatePath, oDocument, oMergedDocument, lclocation
* Create an instance of Word.
RELEASE ALL LIKE o*
PUBLIC oWord
oWord = CreateObject("Word.Application")
* Make Word visible.
oWord.Visible = .t.
* Open a exiting document
lclocation=RTRIM(v_template_letters.tl_location) && set location for letter
odocument=oword.documents.open(lclocation) && open letter
lcFilter = "WHERE " + v_template_letters.tl_filter && get the filter
SELECT Patient_details.pd_pk, Patient_details.pd_title,;
Patient_details.pd_firstname, Patient_details.pd_surname,;
Patient_details.pd_address, Patient_details.pd_street,;
Patient_details.pd_town, Patient_details.pd_county,;
Patient_details.pd_zip;
FROM op!patient_details;
&lcfilter;
INTO CURSOR Addresslist
* Now create and attach a data source
lcheader=RTRIM(v_template_letters.tl_header) && set location for haeder
DO CreateDataSource WITH oDocument, DBF("addresslist"), (lcheader)
USE IN addresslist
* Perform the mail merge
oDocument.MailMerge.Execute()
oMergedDocument = oWord.ActiveDocument
WITH oMergedDocument
IF .ActiveWindow.WindowState <> wdWindowStateMaximize
* Move it to make it visible - for some reason, it comes up
* way off screen
.ActiveWindow.Left = 0
.ActiveWindow.Top = 0
ENDIF
* Preview it
.Printpreview()
ENDWITH
RETURN
Many thnaks for you help
Paul
# 1 Re: Help with Mail Merge and word
On 10 Jul 2003 08:45:17 -0700, "Paul Summerfield"
<foxy@quantumistic.co.uk> wrote:
>
>Sorry but am just getting started with Automation and am finding it a little
>tricky, I have gone through the Automation book which has helped but am
>now a little stuck: -
>
>I have created a letter and attached a header , if I open the letter up in
>word it is all ok and it has the header attached.
>
>My problem is when I run the following code it all opens up and does what
>I think it should be doing but it changes the header and inserts the first
>row into the header so if the header was "pd_surname" it puts in "pd_surname
>smith"
>
Have you changed any of the code in CreateDataSource? What version of
Word are you using?
Also, have you looked at the update for this stuff on the Hentzenwerke
site. After the book was published, we looked at it some more because
we weren't happy with the speed and found an alternate solution using
Excel that's a lot faster.
Tamar
# 2 Re: Help with Mail Merge and word
Many thanks I have downloaded the new excel mail merge and it all works fine,
but I have a little question,
I am setting up my mail merge letter and at the top of the letter I want
<Address>
<Town>
<County>
<Zip>
But I am not sure how to do this I just get them all on one line?
As I have not text I presume I cannot create a bookmark
oRange = oDocument.RANGE(0,0)
WITH oRange
oDocument.MailMerge.FIELDS.ADD( oRange, "pd_address")
.InsertAfter( CR + TAB)
oDocument.MailMerge.FIELDS.ADD( oRange, "pd_street")
.InsertAfter( CR + TAB)
oDocument.MailMerge.FIELDS.ADD( oRange, "pd_town")
.InsertAfter( CR + TAB)
oDocument.MailMerge.FIELDS.ADD( oRange, "pd_county")
.InsertAfter( CR + TAB)
oDocument.MailMerge.FIELDS.ADD( oRange, "pd_zip")
Many thanks
Paul
Tamar E. Granor <> wrote:
>On 10 Jul 2003 08:45:17 -0700, "Paul Summerfield"
><foxy@quantumistic.co.uk> wrote:
>
>>
>>Sorry but am just getting started with Automation and am finding it a little
>>tricky, I have gone through the Automation book which has helped but am
>>now a little stuck: -
>>
>>I have created a letter and attached a header , if I open the letter up
in
>>word it is all ok and it has the header attached.
>>
>>My problem is when I run the following code it all opens up and does what
>>I think it should be doing but it changes the header and inserts the first
>>row into the header so if the header was "pd_surname" it puts in "pd_surname
>>smith"
>>
>
>Have you changed any of the code in CreateDataSource? What version of
>Word are you using?
>
>Also, have you looked at the update for this stuff on the Hentzenwerke
>site. After the book was published, we looked at it some more because
>we weren't happy with the speed and found an alternate solution using
>Excel that's a lot faster.
>
>Tamar
# 3 Re: Help with Mail Merge and word
On 14 Jul 2003 03:33:03 -0700, "Paul Summerfield"
<foxpro@quantumistic.co.uk> wrote:
>
>Many thanks I have downloaded the new excel mail merge and it all works fine,
>but I have a little question,
>
>I am setting up my mail merge letter and at the top of the letter I want
>
><Address>
><Town>
><County>
><Zip>
>
>But I am not sure how to do this I just get them all on one line?
Make sure to insert line breaks in between. In the code you showed,
you don't change the range when you insert the CR. Try adjusting
oRange to follow the new CR.
Tamar
# 4 Re: Help with Mail Merge and word
Opps,
yes all works now many thanks
Word uses a date field that you can select to update automatically, is there
a way to automat this i.e. put this on my letter, to save the user doing
it when i create a template ?
Thanks
Paul
Tamar E. Granor <> wrote:
>On 14 Jul 2003 03:33:03 -0700, "Paul Summerfield"
><foxpro@quantumistic.co.uk> wrote:
>
>>
>>Many thanks I have downloaded the new excel mail merge and it all works
fine,
>>but I have a little question,
>>
>>I am setting up my mail merge letter and at the top of the letter I want
>>
>><Address>
>><Town>
>><County>
>><Zip>
>>
>>But I am not sure how to do this I just get them all on one line?
>
>Make sure to insert line breaks in between. In the code you showed,
>you don't change the range when you insert the CR. Try adjusting
>oRange to follow the new CR.
>
>Tamar
paul at 2007-11-11 23:53:48 >

# 5 Re: Help with Mail Merge and word
On 14 Jul 2003 07:24:34 -0700, "paul " <foxpro@quantumistic.co.uk>
wrote:
>Word uses a date field that you can select to update automatically, is there
>a way to automat this i.e. put this on my letter, to save the user doing
>it when i create a template ?
Yes, you can add fields. Check out the Fields collection,
specifically the Add method.
The field you're interested in is either wdFieldCreateDate or
wdFieldDate.
Tamar