Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Mail Merge with Word 2002
Message
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Titre:
Mail Merge with Word 2002
Divers
Thread ID:
00754387
Message ID:
00754387
Vues:
66
Hi everyone - I am having a bit of trouble getting a mail merge to work with Office XP SP1 (Word 2002). I am using Visual Foxpro 6 SP5 on Windows XP SP1. I have also downloaded and installed the Visual Foxpro driver.

The code was originally written (with help from UT members) for use with Office 2000 and worked OK. It allowed the user to create a mail merge template in Word connecting to the data source using MSQuery to join two tables via the ODBC driver - with our program the user could then pick up the created template and store it so that successive merges could be performed. It was particularly slick or pretty but it gave the users the flexibility they wanted.

I have two problems with this procedure and office XP...

1. I cannot see how to connect two tables and produce a mail merge in office XP (sorry as this is an office question really!)
2. I need some help/ideas with the code to get it working with both Office 2000 and XP.

Here's what we used with Office 2000...
with thisform
local bolObjOk
* check the template
if !file(v_letters.le_path) then
messagebox("      Template not found...          ", OKONLY + STOPICON + FIRSTBUTTON, oApp.ProdName)
return .t.
endif
* get the data for the merge
vPrimary = .pMainPrimary

bolObjOk = .t.
on error bolObjOk = .F.

oWord = getobject("", "Word.Application")
APPLICATION.OLERequestPendingTimeout = 0   
if type("oWord.Name") <> "C"
	messagebox("      Unable to perform the Mail Merge...          ", OKONLY + STOPICON + FIRSTBUTTON, oApp.ProdName)
	return .t.
endif

lcFileName = alltrim(v_letters.le_path)
lnConfirmConversions = 0
lnReadOnly = 0
lnAddToRecentFiles = 0
lcPasswordDocument = ""
lcPasswordTemplate = ""
lnRevert = 0
lcWritePasswordDocument	= ""
lcWritePasswordTemplate	= ""

oWord.visible = .t.

if bolObjOk
	oWord.Documents.Open(;
		lcFileName,;
		lnConfirmConversions,;
		lnReadOnly,;
		lnAddToRecentFiles,;
		lcPasswordDocument,;
		lcPasswordTemplate,;
		lnRevert,;
		lcWritePasswordDocument,;
		lcWritePasswordTemplate )
endif

lcDataFile = oApp.RootFolder + "\data\dbase.dbc"
lcName = oApp.RootFolder + "\data\dbase.dbc"
lnConfirmConversions = 0
lnwdOpenFormatAuto = 0
lnReadOnly = 0
lnLinkToSource = 1
lnAddToRecentFiles = 0
lcPasswordDocument = ""
lcPasswordTemplate = ""
lnRevert = 0
lcWritePasswordDocument	= ""
lcWritePasswordTemplate	= ""

* connection string
lcConnection = "DSN=Visual FoxPro Database;UID=;PWD=;SourceDB=" + lcDataFile + ";SourceType=DBC;Exclusive=No;BackgroundFetch=Yes;Collate=MACHINE;Null=Yes;Deleted=Yes;"
lcSQLStatement = "SELECT * FROM dbase!contacts LEFT OUTER JOIN dbase!addresses ON Contacts.co_primary == Addresses.ad_parent WHERE Contacts.co_primary == " + alltrim(str(vPrimary)) + " AND Addresses.ad_default == 1"
lcSQLStatement1	= ""

if bolObjOk
    oWord.ActiveDocument.MailMerge.OpenDataSource(;
		lcName,;
		lnwdOpenFormatAuto,;
		lnConfirmConversions,;
		lnReadOnly,;
		lnLinkToSource,;
		lnAddToRecentFiles,;
		lcPasswordDocument,;
		lcPasswordTemplate,;
		lnRevert,;
		lcWritePasswordDocument,;
		lcWritePasswordTemplate,;
		lcConnection,;
		lcSQLStatement,;
		lcSQLStatement1 )
		
		* lcConnection + 'SQLStatement:= "'+lcSQLStatement+'"')
		
		
endif

if bolObjOk
	With oWord.ActiveDocument.MailMerge
	    .Destination = 0  && to new file...
	    .MailAsAttachment = 0
	    .MailAddressFieldName = ""
	    .MailSubject = ""
	    .SuppressBlankLines	= 1
	    .Execute(0)
	EndWith
endif

*!*	on error

endwith
The code gets as far as opening the document but doesn't perform the merge. I tried to pick up an error but have been unsuccessful.

thanks
Chris Maiden
Email
Web
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform