Results 1 to 5 of 5
  1. #1
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checking for Open Files (Access 2000)

    Hi all,

    I have one form in an Access ADP project that shows a list of files in a remote server.
    On double click on a list item (file), the form will copy the file to a temporary directory in the local computer (say, "Croject_temp") and then open the file using the shell32.dll library.

    As the project is to be run in several machines, for this to work, when the form opens it checks whether "Croject_temp" exists. If so, it deletes all files in it (so as not to waste disk space). If not, it creates the directory.

    The problem is, when someone opens the form, then double clicks to open (ie, copy to the local machine and open) a file, then closes the form and opens it again WITHOUT closing the open file first, I get Error 70 "access denied" (Access is trying to delete a file in use).

    What I'd like to do is, when someone opens the form, have Access check whether there's an open file in "Croject_temp", and if so, prompt the user accordingly. Any ideas how I can do this (specifically the "are there any open files?" part)?

    Thank you in advance
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Checking for Open Files (Access 2000)

    Put this code in a module:

    Public Function IsFileOpen(FileName As String) As Boolean
    Dim f As Integer
    f = FreeFile
    On Error Resume Next
    Open FileName For Binary Access Read Write Lock Read Write As #f
    Close #f
    IsFileOpen = Not (Err.Number = 0)
    End Function

    Public Function AnyFileOpen(ByVal FolderName As String) As Boolean
    Dim FileName As String
    If Not Right(FolderName, 1) = "" Then
    FolderName = FolderName & ""
    End If
    FileName = Dir(FolderName & "*.*")
    Do While Not FileName = ""
    If IsFileOpen(FolderName & FileName) Then
    AnyFileOpen = True
    Exit Do
    End If
    FileName = Dir
    Loop
    End Function

    Use like this:

    If AnyFileOpen("C:Project_temp") = True Then
    MsgBox "There is an open file.", vbInformation
    Else
    ...
    End If

  3. #3
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checking for Open Files (Access 2000)

    Hello Hans,

    I can't believe a) the VERY short time to reply and [img]/forums/images/smilies/cool.gif[/img] the multiplicity of choices!! The AnyFileOpen function alone would have done perfectly! (in fact, it did <img src=/S/wink.gif border=0 alt=wink width=15 height=15>).

    Thanks <img src=/S/exclamation.gif border=0 alt=exclamation width=15 height=15>
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Checking for Open Files (Access 2000)

    The AnyFileOpen function needs the IsFileOpen function!

  5. #5
    5 Star Lounger
    Join Date
    Mar 2002
    Location
    Buenos Aires, Argentina
    Posts
    877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Checking for Open Files (Access 2000)

    You're right. I'm working with a workmate and after overlooking the code I passed it over to him, who implemented it. I then checked his modified code and rechecked yours, but not just carefully enough. But I didn't lie, your code DID work!!
    Sorry for the mistake <img src=/S/sorry.gif border=0 alt=sorry width=15 height=15> <img src=/S/stupidme.gif border=0 alt=stupidme width=30 height=30> <img src=/S/doh.gif border=0 alt=doh width=15 height=15>
    <img src=/w3timages/blue3line.gif width=33% height=2>
    <img src=/S/flags/Argentina.gif border=0 alt=Argentina width=30 height=18> <big><font color=4682b4><font face="Comic Sans MS">Diegol</font face=comic></font color=4682b4> </big>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •