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!

Sub routine - Help

Status
Not open for further replies.

DotNetGnat

Programmer
Mar 10, 2005
5,548
IN
Hello Guys,

can some one give me a sample code for the below logic...
Code:
Sub main()
'declare the variable that holds the file path
'check to see if that file is already in use
'if the file is in use
'display a message box that says "file is in use"
'else
'display a message box that says "file is not in use"
end if
End sub

The file in the both code is on our network and around 200 people have access to it, so we are not sure if the file is already in use by someone...

the only difficult thing to code for me is HOW TO FIND OUT IF THE FILE ON THE NETORK IS ALREADY IN USE BY SOMEONE programatically

Thanks in advance

-DNG
 
Yes, we definitely need more info. Your question has to be backed up with some hard information.

OS?

What application is running while you check this. Word? Excel? Access?

Permission rights are going to be a huge factor.

Gerry
See my Paintings and Sculpture
 
Well it depeneds on the type of file it is and on your os version...

can u be more specific...is it in a folder that requires access rights is sometimes an issue too...
 
Hi DotNetGnat,

It is probably as easy as anything else to try to open the file exclusively as a text file - if it works, no-one else has the file - if it fails it is most likely because someone else has it open. Something like
Code:
[blue]Dim FileName As String
FileName = "C:\Full\Path\To\File.doc"

On Error Resume Next
Open FileName For Input Lock Read As #1
If Err.Number <> 0 Then
    MsgBox "Someone else has the file open"
Else
    Close #1
    MsgBox "File is available"
End If[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
Excel VBA Training and more Help at VBAExpress[
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top