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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file already open 1

Status
Not open for further replies.

vechalapu

Programmer
May 2, 2001
58
US
hi,

When try to open a file in Vb 6.0, I am getting error 'file already open'. Is there any way to check, if the file is open or not, so that I need to open the file again. The file is stored on a network so I do'nt have too much control over the file.

Thanks
 

Give this a try

[tt]
Public Function IsFileOpen(PathToFile As String) As Boolean

On Error GoTo IsFileOpenError

Open PathToFile For Input Lock Read Write As #yourfilenumb

Exit Function

IsFileOpen = True

End Function

[/tt]


Good Luck

 
VB returns error 55 if the file is open. Check for the error number. CLose the file if you encounter the error and then re-open it..

Sample:

Private Sub Command1_Click()
On Error GoTo Errh
Open "C:\Temp.txt" For Input As #2
MsgBox "File opened sucessfully"

Errh:
If Err.Number <> 0 Then
If Err.Number = 55 Then
MsgBox &quot;File is open lets close it.&quot;
Close #2
Else
MsgBox Err.Number & &quot; &quot; & Err.Description
End If
End If
End Sub

Hope this helps

Thanks Murali Bala
 
That helps in general, but in my case I did not open the file and have to get access. Is there any way to find out which application has grabbed access / opened the file? Or is there any possibility to force close - so that I may get access?
-- same questions to permission denied - error 70
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top