How to check if a doc is open...

xhostarxhostar Member Posts: 2
Hello all:

I have a question... :?:

I need to know if a document is being opened at this moment, so, if another user try to open it, can show a message like: "This document is in use, try later...".

I have a table named "Documents". Each record is a physical document in my pc:

This is the situation:

* I open a document (word,excel... any other) from within Nav.
* Just before open it, mark as TRUE a boolean field named "In Use".
* If another user try to open the same doc, if "In Use" is true, the message "This doc. is being used...." appears.
* When the first user close the application, Navision change the field "In Use" to FALSE.

This is my code:
VARS
WSHShell Automation 'Windows Script Host Object Model'.WshShell
AppExe Text
WinStyle Variant
bWaitOnReturn Boolean

CODE
IF RecDoc.InUse = TRUE THEN
  ERROR('The document %1 is being used...',RecDoc.Name);


IF ISCLEAR(WSHShell) THEN 
  CREATE(WSHShell);
AppExe := '"C:\MyExeProgram.exe " "' + RecDoc.Name + "';
WinStyle := 1;
bWaitOnReturn := TRUE;

RecDoc.InUse := TRUE;
RecDoc.MODIFY;

WSHShell.Run(AppExe,WinStyle,bWaitOnReturn);

RecDoc.InUse := FALSE;
RecDoc.MODIFY;

This code runs ok but there is a problem. Because bWaitOnReturn is TRUE, Navision hopes the application ends, and then, the user cannot work in any other form.

Thanks.

Comments

  • WaldoWaldo Member Posts: 3,412
    That's why Navision (or Microsoft) created something like the WordHandler and the "wrdHandler.WaitForDocument" (search in codeunit 5054).

    You'll have to be quite inventive to solve this one. Look at this post:
    http://www.mibuso.com/forum/viewtopic.php?t=14282&highlight=client1.

    May be this quote from Ara3n:
    How about try to copy the executable from that location to a temp location and delete the executable and copy it back if you succeed.

    Eric Wauters
    MVP - Microsoft Dynamics NAV
    My blog
Sign In or Register to comment.