txtdosya adlı metin kutusu dosya adı ve yolunu eklediğim alan
eğer dosyamız D:\Desktop\AccessDeneme\64bitçalıştırma.doc isemetin kutusuna D:\Desktop\AccessDeneme\64bitçalıştırma.doc yazıyorum
önce aşağıdaki fonksiyonu tanımlıyoruz
Function FileLocked(strFileName As String) As Boolean
On Error Resume Next
' If the file is already opened by another process,
' and the specified type of Access is not allowed,
' the Open operation fails and an error occurs.
Open strFileName For Binary Access Read Lock Read As #1
Close #1
' If an error occurs, the document is currently open.
If Err.Number <> 0 Then
FileLocked = True
Err.Clear
End If
End Function
daha sonrada buton olayına aşağıdaki kodu yazıyoruzPrivate Sub btnDosyaAcikmi_Click()
If Not FileLocked(Me.txtdosya) Then
MsgBox (Me.txtdosya & "dosyas kapal?")
Else
MsgBox (Me.txtdosya & "dosyası açık")
End If
End Sub
yalnız önemli bir noktayı belirteyim; bu kodlar word Excel yada Access gibi açtığı dosyaları kilitleyen programlarda çalışırmesela bir word belgesi eğer wordpad ile açılmışsa kodlar o dosya kapalı der
dilerim işinize yarar