Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word & Fox

Status
Not open for further replies.

dellyjm

Programmer
Apr 13, 2000
168
JM
If I open a Word Application from within fox.

wrdApp = GetObject("","Word.Application")
docFile = "c:\hrm2001\" + alltrim(thisform.txtDocId.value)+".doc"

With wrdApp
.Visible = .T.
.WindowState = 1
.Documents.Add
With .ActiveDocument.MailMerge
.MainDocumentType = 0
.OpenDataSource("C:\HRM\hrempl01.dbf")
EndWith
ENDWITH

How can i know if the user closed the window?

Delton.

 
Hi!

What you meant 'Closed the window'? closed the Word or document? As about document, look to the active document properties and check if that document name is the same. You can save the reference to the active document and check if it is available. For Word check if reference to Word is still available. Bothe could be done using ON ERROR command (if you do not have any code in Error event of the controls).

Code sample:

lcOldError = ON('ERROR')
ON ERROR llError=.T.
provate llError
loDocRef = wrdApp.ActiveDocument
llError = .F.
lOpened = .T.
DECLARE integer Sleep in Win32API integer
do while lOpened
Sleep(100) && wait 0.1 second to free processor time
= wrdApp.Visible && just to get error
&& if Visible property no longer accessible
= loDocRef.... && the same for document - just to
&& evaluate any simple property
lOpened = !llError
enddo
&& close the Word
llError = .F.
= wrdApp.Visible
if !llError && Word is not closed, only document is closed
wrdApp.Quit && Am I correct here? Did not worked with Word so far
release wrdApp
endif
&& restore error handler
ON ERROR &lcOldError
Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
You could also try this:
Code:
if type("wrdApp.Name")='C'
  if type("wrdApp.ActiveDocument")='O'
    ?"Word is open, has active document"
  else
    ?"Word is open, no active document"
  endif
else
  ?"Word is not open"
endif
The TYPE command will return 'U' if the item you specify doesn't exist. In the case of the App itself, however, it will return an 'O' even if the App has been closed, thus I put the App.Name property, which will not exist if the App has been closed.
 
Thanks for all your help guys. It's been helpful.

Delton.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top