Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word merge help
Message
De
03/12/1998 08:19:30
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Fonctions Windows API
Titre:
Divers
Thread ID:
00163320
Message ID:
00163592
Vues:
21
>You seem to be the VFP2Word Wizard :) so here it goes.
>I would like to close the original template file after the merge file have been created. Right now, when Word shows, there are 2 documents (new template file and mail merge created document) open.
>
>code snipplet below:
>
>WITH oWordDocument
> .FileNew(lcTemplate)
> .MailMergeOpenDataSource(cDataFile,,,,,,,,,,,cDSN,cSQLStatement,1)
> .MailMergeToDoc
> .AppShow
>ENDWITH
>
>Any suggestions? TIA.
John,
Thanks for your kind words. I feel like Merlin :) Unfortunately there is no fileclose (or docclose) with an optional filename. So you should use a workaround (save active window number, when ready activate the window, fileclose).
**************************************************
* Start of code
**************************************************
PUBLIC oWordDocument
*** set the LOCALEID to English
nlLocaleId=sys(3004)		&& Save local id
=sys(3006,1033)			&& We will be sending instructions in English
WAIT window nowait "Creating Word Document..."     && Inform user
oWordDocument=createobject("word.basic")	&& Create word object
WITH oWordDocument
  .filenew("c:\temp\mmtemplate.doc")   && open using template table
  * This needs template file already EXISTS !
  * Template based on testdata!employee for sampling
  
  cDSN = "DSN=Visual FoxPro Tables;UID=;PWD=;"
  cSourceDb = "SourceDB="+home()+"SAMPLES\DATA\Testdata.dbc"
  cSourceType = ";SourceType=DBC;"
  cOther = "Exclusive=No;BackgroundFetch=No;Collate=Machine;"

  cSQLStatement = "SELECT * FROM employee where title like [Sales%]"
  * Be carefull with where clause - where title = [Sales] fails
  * for ODBC uses ANSI SQL (exact match)
 .MailMergeOpenDataSource(,,, 1 ,,,,,,,;
	cDSN+cSourceDb+cSourceType+cOther, ;
        cSQLStatement) && Open data source - Link to source
 .MailMergeEditMainDocument	&& Activate the main document
 lnActiveWindow = ltrim(str(.window()))    && Get active doc window number
 .MailMergeToDoc          && Merge to a new document
                          && To print directly: .MailMergeToPrinter
 .window&lnActiveWindow   && Activate template window
 .fileclose(2)            && Close file
 wait clear
 .appshow                 && Show word app
  
ENDWITH

**** Set the LocaleId to the previous value
=sys(3006,val(nlLocaleId))

**************************************************
* End of code
**************************************************
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform