Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word seems to cause Adir failure...
Message
De
19/09/2001 00:22:59
 
 
À
19/09/2001 00:03:36
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00558184
Message ID:
00558190
Vues:
15
>How are you opening & closing Word? Just a SWAG, but I'm wondering if Word is fully closed when you issue your ADIR() - if not, it might include a Word temp file that gets deleted by Word moments later.
This is routine for Word....

PROCEDURE Click
* Allow the user to define a document
* User must surround the document name with tags
* begin tag is <<
* end tag is >>
* Must include full drive:\pathname\filename
* ie. <>
* Also the user might have done a dblClick and not wanted
* to do this so allow them a way out...
local ptr, cString, cFile, nAns
cString = THISFORM.TEXT3.VALUE
if at("<<",cString) > 0 .AND. at(">>",cString) > 0
*!* We have a file name seperate it out and
*!* check for it's existance...After insuring user
*!* actually wanted to do this...
nAns = MessageBox("You have selected to Look at a Document"+chr(10)+"Continue?", 64)
* if nAns > 0 && User Selected to Continue
cFile = subs(cString,at("<<",cString)+2)
cFile = subs(cFile,1,at(">>",cFile)-1)
*!* We know the file name
if file(cFile)
*!* We have found the file fire Word and load it
*!* with this file....
*!* LoadWord(cFile)
nAns = MessageBox("Found file "+cFile+' Ans = '+ltrim(str(nAns)), 64)
do WordMrge with cFile,"..\data\notedat4.dbf"
endif
* endif
endif
ENDPROC
**************** Code for WordMrge follows....
** Mail merge Letter/Label file
** Mail merge Data Source file
lParameters lcMMLetterFile, lcMMDataFile

local lcErrorHold
lcErrorHold = on( "error" )
llObjOk = .T.
on error llObjOk = .F.

oWord = getobject( "", "Word.Application" )
if type( "oWord.Name" ) <> "C"
lcMsg = "I am unable to load/locate Word 2000" +chr(13);
+ "to complete mail merge process."
Messagebox( lcMsg, 0, "Unable to merge" )
return
endif

*/ Don't keep re-opening multiple instances of Word...
*/ use existing... USE OBJECT BROWSER... Shows all
*/ word crap, parameters, objects, properties, methods, etc
*/ Parameters to Word, logical True/False values
*/ are numeric based... 0 = FALSE
lcFileName = lcMMLetterFile
lnConfirmConversions = 0
lnReadOnly = 0
lnAddToRecentFiles = 0
lcPasswordDocument = ""
lcPasswordTemplate = ""
lnRevert = 0
lcWritePasswordDocument = ""
lcWritePasswordTemplate = ""

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

lcRootPath = left( lcMMDataFile, rat( "\", lcMMDataFile ) -1 ) + ";"
lcDataFile = substr( lcMMDataFile, rat( "\", lcMMDataFile ) +1 )
lcName = lcMMDataFile
lnConfirmConversions = 0
lnwdOpenFormatAuto = 0
lnReadOnly = 0
lnLinkToSource = 1
lnAddToRecentFiles = 0
lcPasswordDocument = ""
lcPasswordTemplate = ""
lnRevert = 0
lcWritePasswordDocument = ""
lcWritePasswordTemplate = ""
lcConnection = "DSN=FoxPro Files - Word;UID=;PWD=;";
+ "SourceDB=" + lcRootPath ;
+ "SourceType=DBF;Exclusive=No;";
+ "BackgroundFetch=Yes;Collate=MACHINE;";
+ "Null=Yes;Deleted=Yes;"

lcSQLStatement = "SELECT * FROM " + lcDataFile
lcSQLStatement1 = ""

*/ If no errors yet by the above opening document,
*/ object references, etc trapped by ON ERROR...
if llObjOk
oDoc = oWord.Documents(1)
endif

if llObjOk
oDoc.MailMerge.OpenDataSource(;
lcName,;
lnwdOpenFormatAuto,;
lnConfirmConversions,;
lnReadOnly,;
lnLinkToSource,;
lnAddToRecentFiles,;
lcPasswordDocument,;
lcPasswordTemplate,;
lnRevert,;
lcWritePasswordDocument,;
lcWritePasswordTemplate,;
lcConnection,;
lcSQLStatement,;
lcSQLStatement1 )
endif

if llObjOk
With oDoc.MailMerge
.Destination = 0 && to new file...
.MailAsAttachment = 0
.MailAddressFieldName = ""
.MailSubject = ""
.SuppressBlankLines = 1
With .DataSource
*/ wdDefaultFirstRecord 1
*/ wdDefaultLastRecord -16
.FirstRecord = 1
.LastRecord = -16
EndWith
.Execute(0)
EndWith
endif


*/ Now, print it...
lnBackground = 1
lnAppend = 0
lnRange = 0
lcOutputFileName = ""
lnPageFrom = 1
lnPageTo = 5
lnItem = 0
lnCopies = 1
lcPages = ""
lnPageType = 0
lnPrintToFile = 0
lnCollate = 1
lcFileName = ""
lnActivePrinterMacGX = 0
lnManualDuplexPrint = 0
lnPrintZoomColumn = 0
lnPrintZoomRow = 0
lnPrintZoomPaperWidth = 0
lnPrintZoomPaperHeight = 0

*/ disabled this to automatically print document
*oWord.Application.PrintOut()


*/ But I just changed it to VISIBLE = .T. so users
*/ could pre-review the output before final printing
*/ and make necessary edits beforehand.
oWord.Visible = .T.

*/ This would force close the word document
*/ Parameter = 0 means don't prompt to save changes...
* oWord.Documents.Close(0)
oWord.Documents.DisplayAlerts = .F.
oWord.Documents.SaveAs(lcMMLetterFile)
*oWord.Documents.Close(0)
*/ Restore error handler
on error &lcErrorHold

return
******************* End of WordMrge.prg
Minor changes to original from UT download....


>
>>Hi All,
>>
>>In my application the end user has the ability to view a file in Word..Then when exiting I create an automatic backup to 1 of 7 directories based on where he last backup to. code is below. When they exit if they have opened word the backup fails with an file open error on whatever the first file is that Adir returns. Can you help? Thanks in Advance.
>>Cecil...
>>
>>use ..\data\sysprefs
>>nBack=sysprefs.lastbackup +1
>>if nBack < 7
>> repl sysprefs.lastbackup with nBack
>>else
>> repl sysprefs.lastbackup with 0
>>endif
>>messagebox("Backing up data please wait",64,"Back Up")
>>cBack="\frontsol\backup\"+ltrim(str(nBack))+"\" && \frontsol\backup\1, \frontsol\backup\2 etc...
>>*!clf!* New routine for backups...
>> nDbfs = Adir(aDbfs,"..\data\*.dbf")
>> close databases all && Close all open databases
>> close tables all && Close all open tables
>> clear
>> for i = 1 to nDbfs
>> cFile = aDbfs(i,1)
>> @ 14,10 say "Backing up "+ left(cFile+space(25),25)
>> cFile2 = "..\data\"+cFile
>> use (cFile2) in 0 exclusive
>> nRec = Reccount()
>> @ 15,10 say "Creating "+ left(cBack+cFile+space(50),50)
>> copy to (cBack+cFile)
>> use (cBack+cFile)
>> if reccount()<>nrec
>> @ 16,10 say 'Error in table '+cFile
>> endif
>> use
>> endfor
>>*!clf!* Will finally back it up...
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform