locked without actually connecting to the database, such as to do an administrative chore like a repair/compact or file backup.
In this circumstance, the IsDBOpenedExclusively(sPathToDB) routine documented in Microsoft's Jet Database Developer's Guide may be too much because it works by trying to make a connection and returns whether it could connect or not. Why put the dbengine through all that work?
Consider, if you send a Jet database to Notepad and the file is not exclusively locked then the file will open as an ascii file. However if you send a Jet file that is already opened exclusively to notepad you will receive a file permission error from the OS. This tip routine builds off of that knowledge. Just pass the database path to the function and check the return.
Public Function DBInUseExclusively(byval sPathToJetDB as string) As Boolean
'by smith www.smithvoice.com
'called when there is no lock file
'just attempts to open the database and looks for
a file permission denied error
'
'you should do a FileExist on the path
prior to this function to head off
'invalid path statements, a good
'one can be found at: http://www.smithvoice.com/fileexis.aspx
Dim FileNumber As Integer
FileNumber = FreeFile
On Error Resume Next
Open sPathToJetDB For Input As FileNumber
Close FileNumber
If Err.Number = 70 Then
DBInUseExclusively = True
Err.Clear
Else
DBInUseExclusively = False
End If
End Function
Try this on other lockable ISAMs for the same reasons.
Hope it helps.
Robert Smith
Kirkland WA
added to smithvoice july 1999