I'm using VFP9SR2 and trying to do a mail merge 2ith MSWord2003.
My problem is that under code my template will not automatically merge. I have to manually select the Excel Table from the merge tool bar then view the merged data.
If I open it from Word, or double click it from windows Explorer, Word brings up a Dialog box asking if I want to run an SQL command.
I've apparantly done something stupid with the link to the mail letter and the data source but, I don't know what.
Any help will be greatly appreciated. I'm a rookie at this!
I'm using the following code:
#DEFINE wdMainAndDataSource 2
#DEFINE wdSendToPrinter 1
#DEFINE wdDoNotSaveChanges 0
CLOSE TABLES all
USE ccauth
COPY TO ccauth TYPE xl5
CLOSE TABLES all
oWord = CREATEOBJECT("Word.Application")
oWord.Visible = .t.
** change the path and file name to suit
oWord.Documents.Open("C:\_0_applications\myTempl.dot")
** check to make sure the documnet is attached to a
** datasource and ready to merge.
If oWord.ActiveDocument.MailMerge.State = wdMainAndDataSource
oWord.ActiveDocument.MailMerge.DataSource.FirstRecord = 1
oWord.ActiveDocument.MailMerge.DataSource.LastRecord = 1
oWord.ActiveDocument.MailMerge.Execute
endif
Code I'm planning to add later:
*oWord.ActiveDocument.PrintPreview()
*oWord.Quit(wdDoNotSaveChanges) && close file no save
release oWord
** property to retrive OR set the first record to print
*oWord.ActiveDocument.MailMerge.DataSource.FirstRecord
** property to retrive OR set the last record to print
*oWord.ActiveDocument.MailMerge.DataSource.LastRecord
My problem is that under code my template will not automatically merge. I have to manually select the Excel Table from the merge tool bar then view the merged data.
If I open it from Word, or double click it from windows Explorer, Word brings up a Dialog box asking if I want to run an SQL command.
I've apparantly done something stupid with the link to the mail letter and the data source but, I don't know what.
Any help will be greatly appreciated. I'm a rookie at this!
I'm using the following code:
#DEFINE wdMainAndDataSource 2
#DEFINE wdSendToPrinter 1
#DEFINE wdDoNotSaveChanges 0
CLOSE TABLES all
USE ccauth
COPY TO ccauth TYPE xl5
CLOSE TABLES all
oWord = CREATEOBJECT("Word.Application")
oWord.Visible = .t.
** change the path and file name to suit
oWord.Documents.Open("C:\_0_applications\myTempl.dot")
** check to make sure the documnet is attached to a
** datasource and ready to merge.
If oWord.ActiveDocument.MailMerge.State = wdMainAndDataSource
oWord.ActiveDocument.MailMerge.DataSource.FirstRecord = 1
oWord.ActiveDocument.MailMerge.DataSource.LastRecord = 1
oWord.ActiveDocument.MailMerge.Execute
endif
Code I'm planning to add later:
*oWord.ActiveDocument.PrintPreview()
*oWord.Quit(wdDoNotSaveChanges) && close file no save
release oWord
** property to retrive OR set the first record to print
*oWord.ActiveDocument.MailMerge.DataSource.FirstRecord
** property to retrive OR set the last record to print
*oWord.ActiveDocument.MailMerge.DataSource.LastRecord