Solved

file locking

Posted on 2002-05-07
5
165 Views
Last Modified: 2010-05-02
I need to establish whether a file is locked by another user.
0
Comment
Question by:DAVIDW
5 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 6993735
What sort of a file?
0
 

Author Comment

by:DAVIDW
ID: 6993753
A TEXT FILE
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 6993762
This is not necessarily as simple as it may seem, a text file may be opened for reading without placing a lock on the file. The best thing to do is basically attempt to place a lock on the file of the type that you require:

On Error Resume Next
Open "MyFile.txt" For Binary Access Write As #1
If Err.Number <> 0 Then
  Msgbox "Error locking file"
Else
  Close #1
End If

This will basically attempt to open the file for binary write. If it succeeds then you can be fairly certain that the file is not locked by any other user.

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7722352
Hi DAVIDW,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept TimCottee's comment(s) as an answer.

DAVIDW, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7780044
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now