Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word Merge Help...
Message
From
30/01/2008 00:24:07
Chris Sund
Silhouette Solutions
Utah, United States
 
 
To
29/01/2008 17:09:42
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Miscellaneous
Thread ID:
01286305
Message ID:
01287002
Views:
44
Hi Cetin,

I was able to get everything working beautifully with a txt document. I mixed and matched your code with my original code, and everything renders perfectly. I had some problems geting my "Preview Results" to work, but found it was a setting in my Word Software. I created a seperate post on that..

http://www.levelextreme.com/wconnect/wc.dll?2,15,1286995

I appreciate your help, here's my code, if you see any inherent issues let me know. I'll be honest and say, I'm not sure I need every line that's in the code, but it's working so I didn't want to mess with it too much. I wish there was a help document on the mailmerge object along with the Word.application object. It seems every document I have found says something a little different, and alot of them aren't directed towards VFP. Oh Well, that's why we have UniversalThread!

By posting the code, maybe it will help someone else down the line.
LPARAMETERS pdocument, pprop_key



#DEFINE wdMainAndDataSource 2
#DEFINE wdSendToPrinter 2
#DEFINE wdDoNotSaveChanges 0
#DEFINE wdWindowStateMinimize 2
#DEFINE wdOpenFormatText 4

SET MEMOWIDTH TO 255

Local nLocaleID,lcTemp,lcHeader
Local loWord,llToPrinter,lcSourceDoc

*#include "wdconst.h"


SET SAFETY OFF

CD C:\VPMAPPS\TLP

*!*	OPEN DATABASE ATLP_V SHARED
*!*	SELECT * FROM property_v WHERE .t. INTO CURSOR t1


jprop_key=pprop_Key

SET MEMOWIDTH TO 255

Select;
 cprimary_owner as OwnerName,;
cname2,;
cname3,;
cco_line as CareOfName,;
caddress_b as Address,;
ccity_a as City,;
cstate_b as StateOrProvince,;
czip_a as PostalCode,;
cname as CountyName,;
caddress_c as CountyAddress1,;
caddress2 as CountyAddress2,;
ccity_b as CountyCity,;
cstate_c as CountyState,;
czip_b as CountyZip,;
cphone_b as TreasurerPhone,;
ctownship as TownshipRange,;
csection as Section,;
nparcel_no as ParcelNumber,;
MLINE(clgl_desc,1) as LegalDescription,;
MLINE(cgeocode,1) as Geocode,;
SPACE(10) as DateOfNotice;
 From property_v Where cprop_pk=jprop_key And .T. Into Cursor merge_cursor readwrite

IF !EMPTY(jdate_of_notice)

REPLACE DateOfNotice WITH DTOC(jdate_of_notice) all


endif

SELECT merge_cursor
lctemp=CURDIR()+'form_letters\tlp.tmp'
Copy To (lctemp) Type Delimited With "" With Tab
AFIELDS(laFields)
lcHeader = ''
For ix = 1 To Fcount()
    lcHeader = lcHeader + ;
        Iif(Empty(m.lcHeader),'',Chr(9)) + ;
        Field(m.ix)
Endfor

lcSourceDoc = CURDIR()+'form_letters\mergesource.txt'
Strtofile(lcHeader+Chr(13)+Chr(10)+Filetostr(lcTemp),lcSourceDoc)



WAIT WINDOW NOWAIT 'Creating Word Merge Document...'

oWord = CREATEOBJECT("Word.Application")
oWord.Visible = .T.


oDoc = oWord.Documents.Open(CURDIR()+"form_letters\"+pdocument)
	oDoc.MailMerge.MainDocumentType = 0
	oDoc.MailMerge.OpenDataSource(lcSourceDoc)

	oDoc.MailMerge.DataSource.FirstRecord =  oDoc.MailMerge.DataSource.ActiveRecord
	   oDoc.MailMerge.DataSource.LastRecord = oDoc.MailMerge.DataSource.ActiveRecord
	   
	   oDoc.activate && Make it the active foreground app

	   *oDoc.MailMerge.Execute
Previous
Reply
Map
View

Click here to load this message in the networking platform