Stretchwickster
Programmer
Currently, I'm using the following code to see if a file is already open. It works fine. However, I now have a shared file and it doesn't detect if this file is already open. Does anyone have a solution regardless of whether the file is shared or exclusive.
Clive![[infinity] [infinity] [infinity]](/data/assets/smilies/infinity.gif)
Ex nihilo, nihil fit (Out of nothing, nothing comes)
Code:
Function FileIsOpen(AFileName As String) As Boolean
On Error Resume Next
FileIsOpen = False
' If the file is already open & file access is disallowed,
' the Open operation fails and an error occurs.
Open AFileName For Binary Access Read Lock Read As #1
Close #1
' If an error occurs, the file is currently open.
If Err.Number <> 0 Then
FileIsOpen = True
MsgBox "Unable to open " & AFileName & vbCrLf & "A file with this name is already open", vbExclamation
Err.Clear
End If
End Function
Clive
![[infinity] [infinity] [infinity]](/data/assets/smilies/infinity.gif)
Ex nihilo, nihil fit (Out of nothing, nothing comes)