Test for WP file already open?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to test to see if the user already has an existing WordPerfect
document open. WordPerfect gives the user a read-only warning message but
still allows the user to open a 2nd instance of the file. I need to prevent
this if only by forcing the application to set the focus on the already open
version of the existing document.

My code thus far to open the file looks something like this:

Set wpApp = CreateObject("WordPerfect.PerfectScript")
wpApp.WPActivate
wpApp.AppMaximize
wpApp.FileOpen (stFileName)


Any advice?
 
Does WP have a collection of open documents that you can loop through to see
what's currently open?
 
Yes, WP has the "ThisDocument" collection but that only runs from within the
WP document. I can't access it from within Access. I need to run this code
from within Access so that Access will not re-open the document for the user
if the user already has it open.
 
You'll have to delve a little deeper into automating WP, then, as this isn't
really an Access issue.

I would have expected you to be able to do something like

wpApp.ThisDocument

However, you instantiated wpApp as WordPerfect.PerfectScript

Perhaps you need to instantiate it as, say WordPerfect.Application, and then
instantiate that instance's PerfectScript object.
 
Hi Sandie,

I'd follow up Doug's suggestion if possible: it's far the most direct
approach. But if WordPerfect really can't tell you what documents it has
open, it's worth trying the old-fashioned trick of trying to gain
exclusive access to the file you're interested in, e.g. this air code:

Dim lngFN as Long

LngFN = FreeFile()
On Error Resume Next
Open strFileSpec For Binary Access Read Lock Read Write As #lngFN
If Err.Number <> 0 Then
'Something else has the file open
Err.Clear
Else
'We have the file, therefore nothing else does
Close #lngFN
End If
On Error Goto 0

Another possibility - if WP creates a temporary file foe every file it
has open (as Word does) is to test whether that file exists and has a
plausible timestamp.
 
Back
Top