>>>Hi,
>>>
>>>The only way I know how to determine if a table is already open under some unknown alias is by trying to open the table exclusive and catching the error. Is there another way, maybe simpler?
>>>
>>>TIA.
>>
>>
>>TRY
>> USE YourTable IN 0 EXCLUSIVE
>>CATCH
>> MessageBox("The Table is already opened somewhere")
>>ENDTRY
>>
>
>Thank you, Borislav. This works but I forgot to mention that I am trying to find out if the file/table is open by "this" user and not by anyone. That is, if another user of this application has this file open (maybe on another computer), the above code will say that the file is already open. But to me this is not important; I need to find out if this datasession has the file open. Do you see what I mean?
lnUsedFiles = AUSED(laUsed)
lbAlreadyUsed = .f.
FOR lnFor = 1 TO m.lnUsedFiles
IF UPPER(JUSTFNAME(DBF(laUsed[lnFor]))) = "THENAMEOFTHEDBF.DBF"
lbAlreadyUsed = .t.
EXIT
ENDIF
NEXT
IF m.lbAlreadyUsed
MessageBox("The Table is used in this datasesion")
ENDIF
This way wouldn't work if you try to open a DBF placed in c:\test but you already opened the DBF with the same name placed in c:\OtherFolder. If you want to check for this just add the full path in the IF
...
FOR lnFor = 1 TO m.lnUsedFiles
IF UPPER(DBF(laUsed[lnFor])) = "FULL_PATH_TO_TABLE\THENAMEOFTHEDBF.DBF"
lbAlreadyUsed = .t.
EXIT
ENDIF
NEXT
...
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.