Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Copy contents of a general field into the clipboard
Message
From
23/09/2002 16:08:17
 
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
00481684
Message ID:
00703524
Views:
19
Has anyone figured out how to close the WINWORD.EXE process that the oldboundcontrol started?

>Thanks... I'll be waiting with baited breadth. I have logged about 12 hours fighting this beast.
>
>Other information I can offer:
>1. thought it might have to do with the timing of the Release of the form object so I put it after the .WordStart. Didn't matter, as soon as Word starts, and is visible the phantom appears.
>2. I can use the .iowordobject.documents.count (returns a value including the phantom) the .iowordobject.documents.item(n) to retrieve the info but can't .close it
>3. .iowordobject.quit really is not an option given many files may be up at the same time and not all ready to be saved.
>4. .iowordobject.quit does recognize that the document needs to be saved/aborted
>5. Curious, the document is not named Document(n) as it would be if it were created from within Word. it is titled "Document in Unamed". This could be relevant since it was created through the VFP control.
>
>Bottom line: It appears that the solution has to come from the VFP end since it spawned the beast. The oFormReference.destroy or release does not kill it. Perhaps the .content.copy creates some link to the OLEBoundControl to the clipboard and as long as the link exists to the clipboard there is a problem.
>
>Thanks again for your perseverence
>
>Dave
>
>>Hey Dave,
>>
>>I think I can solve this, but I'm on a business trip right now and don't have access to the application that I posted the previous code from. I will reply with a solution when I return to Tallahassee next weekend. Sorry for the wait.
>>
>>>Thanks for the reply John.... don't think our pathes have crossed since Palm Springs.
>>>
>>>Turns out the line I really needed from you was the OLEBound.content.copy which either upsets me because I could not find it in the documentation of the OLEBoundControl or that is was not there.... thanks!
>>>
>>>BUT, a new problem has surfaced. You will notice in the following code block that I do create the form, control, populate it and copy it to the clipboard. The process then uses my custom OLEcontrol to open Word, Open a template, find a bookmark, paste....blah, blah,blah and ends up putting the final clipboard into a patient file. Here's the problem: when Word fires up (.WordStart which uses CreateObject(word.application) or GetObject(,"word.application)) it mysteriously adds a document (Word 2000) with the contents of the clipboard in it (nasty format I might add). I thought this had to do perhaps with the native action of the OLEBoundControl so attempted to use the DoVerb() to stop the unwanted extra document window...to no avail. Try two was to simply go with it and try to close the extra document ("ActiveDocument" tried) but it was not happy either
>>>
>>>Any ideas on getting rid of the extra document without closing Word and re-starting which is not an option for other reasons? One posibility might be to cycle somehow through all documents it thinks is open and issue close statements?
>>>
>>>Dave
>>>
>>>* The general field needs to be made available from within an
>>>* OLEBoundControl since we cannot
>>>* simply write it out with the standard .text method.
>>>* Unfortunately the OLEBoundControl needs to be
>>>* on a form, thus the following gyrations.....
>>>frmWord=CREATEOBJECT("FORM") && Adds OLE object to form
>>>frmWord.ADDOBJECT("OBJWORDDOC","OLEBOUNDCONTROL") && Sets the control source
>>>frmWord.OBJWORDDOC.CONTROLSOURCE="cPaCDRHist.cdrh_genfld"
>>>*frmWord.OBJWORDDOC.DoVerb(-3) && Default Word doc is 'Edit'
>>>frmWord.OBJWORDDOC.Content.copy && Put the contents into the clipboard
>>>Release frmWord && Clean up
>>>
>>>* Let's get into the Word stuff
>>>oWordObject = CreateObject("wxWordInterface") && Droege Custom Class
>>>With oWordObject
>>> .ResetProperties && Clean out
>>> .Wordstart && Start it up
>>>
>>> * for some strange reason, because of the above content.copy, WORD starts
>>> * with a document up with the contents of the clipboard in it so I need to
>>> * take out the trash first
>>> *.ioWordObject.ActiveDocument.Close(.wdDoNotSaveChanges ) && Don't save
>>>
>>> If oWordObject.ilWordStarted && property set in the .WordStart method
>>> .icWordDocFile = lcMainPatFile && Store the Doc file to the object
>>> .icTemplateFile = lcTemplateFile && Store the Template file to the obj
>>>
>>> * Next open the template document in a second window
>>> .TemplateOpen()
>>>
>>> * Let's get the bookmarks for this note stored in Bookmarks.dbf
>>> * and validate that they are all present in the template file
>>> .icBookmarkTable = "Bookmarks"
>>> .icBookmarkTableSrchField = "assocnote"
>>> .icBookmarkTableSrchValue = "CORRECTION"
>>> If .BookmarkValidation()
>>>
>>> * Put the clipboard contents in the bookmark in the template,
>>> * copy it to the clipboard and close it
>>> lcBookMarkName = "CDRH_GENFLD"
>>> * Move to the assocaited bookmark in the template
>>> .ioTemplateObject.Bookmarks(lcBookMarkName ).Select
>>> * paste the clipboard contents into the current document
>>> .ioWordObject.selection.paste
>>> .TemplateCopyToClipboard() && Copy the entire TEMPLATE to the clipboard
>>> .TemplateClose() && Close the Template file
>>>
>>> * Put the final clipboard contents into the patient document
>>> .WordDocOpen() && Open the existing patient document
>>> .WordDocGotoBottom() && move to the bottom
>>> .WordDocPaste() && Write the clipboard
>>> .ioWordObject.Activate && Put Word on top
>>>
>>> Else
>>> =x3WinMsg("The CDRH_GENFLD bookmark is missing in the template file!
>>> Please add it and try again."+CHR(13)+;
>>> "Process aborted","Bookmark missing...","!")
>>> Return
>>> Endif
>>> Else && If oWordObject.ilWordStarted
>>>
>>> =x3WinMsg("Word could not be started properly!"+CHR(13)+CHR(13)+;
>>> "Please check with your computer support to make sure it is
>>> loaded correctly"+CHR(13)+;
>>> "and that the release is at least version 97 SR-2 (Service
>>> Release 2)"+CHR(13)+CHR(13)+;
>>> "This process will not be completed.","Word instantiation
>>> error...",,"S")
>>>
>>>Endif && If oWordObject.ilWordStarted
>>>
>>>Endwith && oWordObject
>>>
>>>* Clean up
>>>oWordObject = .null.
>>>Release oWordObject
>>>
>>>
>>>
>>>>Hi Dave,
>>>>
>>>>This is a major PITA to figure out, but the solution is relatively simple. I have a contract printing application that grabs contract clauses from a table with a General field. To put the clauses one-by-one, I use the following method:
>>>>
>>>>PARAMETERS oOLEBound,oWordRange,cBoundCol,lFormat,lCRLF
>>>>oOLEBound.ControlSource=cBoundCol
>>>>oOLEBound.Content.Copy
>>>>oWordRange.Collapse
>>>>oWordRange.PasteSpecial
>>>>IF lFormat
>>>>   oWordRange.Text=ALLT(oWordRange.Text)+IIF(lCRLF,CHR(13),"")
>>>>ENDIF
>>>>RETURN
>>>>
>>>>This requires you to create a Form and add an OLEBoundControl to it to use as what I call oOLEBound. Also, where you want the contents of the General field, defined as a Word Range object, are required for oWordRange. cBoundCol is the name of the General field. Now note lFormat and lCRLF and what they do...not directly related to your problem but you will find you want to add spacing.
>>>>
>>>>Also not the PasteSpecial. If you don't use that, you'll lose most formatting.
>>>>
>>>>
>>>>>I am creating Word 2000 DOC's via OLE and all works well except for getting the contents of the associated general field into the document. The contents is actually another Word DOC. My class is set up so all I need to do is get it into the clipboard and then issue a Word "paste" since I have already positioned the cursor to the correct location....
>>>>>
>>>>>Any ideas?
>>>>>
>>>>>Thanks in advance!
>>>>>
>>>>>Dave
Previous
Reply
Map
View

Click here to load this message in the networking platform