Determining if a File is Open

  • Thread starter jer99 via AccessMonster.com
  • Start date
J

jer99 via AccessMonster.com

Is there any way to determine if a file is still open that was open using the

Open XXX as #1 ?
 
D

Dirk Goldgar

In
jer99 via AccessMonster.com said:
Is there any way to determine if a file is still open that was open
using the

Open XXX as #1 ?

You could use this function:

'----- start of code -----
Function FileIsOpen(iFileNo As Integer) As Boolean

Dim l As Long

On Error GoTo Err_Handler
l = FileAttr(iFileNo)
FileIsOpen = True

Exit_Point:
Exit Function

Err_Handler:
Resume Exit_Point

End Function

'----- end of code -----

Your code to call it would be:

If FileIsOpen(1) Then
' the file is open
End If

There may be a simpler way, but this is the first that springs to mind.

Incidentally, it's a bad idea to hard-code your file numbers. Instead,
use the FreeFile function to get the first available file-number.
 
Top