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!

Detect if other programs are accessing a file

Status
Not open for further replies.

Custardptt

Technical User
Jan 12, 2005
31
GB
Hi All,

Is there a reliable way of detecting if a file is in use from within Access?

My application needs to access and move files that are placed on the local disk by other applications (on the same PC). I’d like to check to see if anything else is writing to the file first.

Thanks in advance

Pete
 
If you try to open it for read/write denying that to other programs, you'll get and error if it is in use. This Function grabs the error and returns True/False

(Typed, Untested)
Code:
Function CheckAvail(strFile As String)  As Boolean

Dim myFreeFile As Long

On Error Resume Next
myFreeFile = FreeFile
Err.Clear
Open strFile For Random Access ReadWrite LockReadWrite As #myFreeFile
If Err.Number <>0 Then
   CheckAvail=False
Else
   Close #myFreeFile
   CheckAvail=True
End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top