Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Exclusively In Use By Another User

Status
Not open for further replies.

JesseH

MIS
Aug 9, 2001
63
US
I am creating a file to be passed to another application. The problem is that when the file is opened exclusively by the other application, Access closes down in an error condidtion (we are using a max time in a scheduler). Once that happens, we are toast. Question, using code, is there any way to determine that the file is "locked"

Thanks
Jesse
 
Jesse,

You might try the following function to determine whether the file is in use when your app needs to access it. The code is from an example in the API-Guide written by the KPD-Team and obtained from
Code:
'Win32 API Declarations
Declare Function lOpen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
Declare Function lClose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long


Function IsFileAlreadyOpen(FileName As String) As Boolean
' Source: API-Guide at [URL unfurl="true"]http://www.allapi.net/[/URL]
Dim hFile As Long
Dim lastErr As Long
    
   ' Initialize file handle and error variable.
   hFile = -1
   lastErr = 0
   ' Open for for read and exclusive sharing.
   hFile = lOpen(FileName, &H10)
   ' If we couldn't open the file, get the last error.
   If hFile = -1 Then
     lastErr = Err.LastDllError
   Else
    ' Make sure we close the file on success.
     lClose (hFile)
   End If
    
   ' Check for sharing violation error.
   IsFileAlreadyOpen = (hFile = -1) And (lastErr = 32)

End Function

Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top