FoxPro Programming
Mail Merge Visual Foxpro
Just for you information
I do NOT need a responce
PROCEDURE OUT_PUT_TEXT_3017
PARAMETERS mBPNTR AS Integer, mSOURCE AS Integer
* mSOURCE
* 2 - Preview Reports
* 3 - Print
LOCAL gcDelimFile AS STRING
LOCAL mTEST AS String
LOCAL mPATH AS String
gcDelimFile = "C:\RISWIN\TEMP\E1099.XLS"
IF FILE(gcDelimFile) = .T. THEN
mTEST = "DELETE FILE " + ALLTRIM(gcDelimFile)
&mTEST
ENDIF
DO OUT_PUT_BATCH_REPORTS WITH 5, mBPNTR, 4, "", 0, gcDelimFile && -- Creates Excel Spread sheet
IF (IsExeRunning("winword.exe")) = .T. THEN
=MESSAGEBOX("MICROSOFT WORD IS OPEN, PLEASE CLOSE ALL OPEN WORD APPLICATIONS OR RESTART YOUR COMPUTER AND TRY AGAIN")
ELSE
IF (IsExeRunning("excel.exe")) = .T. THEN
=MESSAGEBOX("MICROSOFT EXCEL IS OPEN, PLEASE CLOSE ALL OPEN EXCEL APPLICATIONS OR RESTART YOUR COMPUTER AND TRY AGAIN")
ELSE
mPATH = ALLTRIM(SYSCNTRL.PDRIVE) + "\RISWIN\Letters\FED1099.doc"
IF FILE(mPATH) = .F. THEN
=MESSAGEBOX("THERE IS A MAJOR PROBLEM WITH OUT_PUT_TEXT_3017 - 1099 Mail Merge File NOT FOUND")
CLOSE ALL
QUIT
CANCEL
ENDIF
IF FILE(gcDelimFile) = .F. THEN
=MESSAGEBOX("THERE IS A MAJOR PROBLEM WITH OUT_PUT_TEXT_3017 - 1099 Mail Merge DATAS NOT FOUND")
CLOSE ALL
QUIT
CANCEL
ENDIF
LOCAL oApp As Word.Application
LOCAL oDoc As Word.Document
oApp = CREATEOBJECT("Word.Application")
oDoc = oApp.Documents.Open(mPATH)
oApp.ActiveDocument.MailMerge.OpenDataSource( gcDelimFile, ; && 01 - Name - Data Source File Name
0, ; && 02 - Format - wdOpenFormat
.F.,; && 03 - ConfirmConversions - Display Convert File Dialog Box
.F.,; && 04 - ReadOnly
,; && 05 - LinkToSource - Perform Query Specified by Connection & SQL Statement Each Time
.F.,; && 06 - AddToRecentFiles - Add File Name to the List of Recently Used Files in File Menu
,; && 07 - PasswordDocument - Password Used to Open the Data Source
,; && 08 - PasswordTemplate - Password used to Open the Template
,; && 09 - Revert - Controls what happens if Name is the file name of an Open Document
,; && 10 - WritePasswordDocument - Password used to save changes to the document
,; && 11 - WritePasswordTemplate - Password used to save changes to the template
,; &&'TABLE YourTable',; && 12 - Connection - A Range within which the Query Specified by SQLStatement is to be performed
'SELECT * FROM [Sheet1$]',; && 13 - SQLStatement - Defines Query options for retrieving data
,; && 14 - SQLStatement1 - Used if the query string is longer than 255 characters
,; && 15 - OpenExclusive - .T. to open exclusively
) && 16 - SubType -
oApp.ActiveDocument.MailMerge.Execute
IF mSOURCE = 3 THEN && -- Print
oApp.PrintOut()
mTEST = "WAIT 'PRINTING' WINDOW TIMEOUT 1"
&mTEST
DOEVENTS
oApp.NormalTemplate.Saved = .T.
oDoc.Close(0)
oApp.Quit(0)
ELSE
oApp.Visible = .T.
=MESSAGEBOX("CONTINUE")
ENDIF
DO WHILE .T.
IF (IsExeRunning("winword.exe")) = .T. THEN
mTEST = "WAIT 'WAITING FOR WORD TO CLOSE' WINDOW TIMEOUT 2"
&mTEST
ELSE
mTEST = "WAIT 'WORD HAS CLOSED' WINDOW TIMEOUT 2"
&mTEST
EXIT
ENDIF
ENDDO
ENDIF && -- IF (IsExeRunning("excel.exe")) = .T. THEN
ENDIF && -- IF (IsExeRunning("winword.exe")) = .T. THEN
ENDPROC