Results 1 to 6 of 6
  1. #1
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150

    Check if a file is open


    I've searched and used various codes that I can find on the net, but they don't seem to work. I basically want to check if a file is open. Does anyone have a function that works?

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722

  3. #3
    LonghronJ is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    150
    Quote Originally Posted by orange View Post
    Thanks, Orange, but regardless which function I've used, I keep getting ErrNum of 53 whether a file is open or not. Therefore, it's always considered open.

    Code:
    Select Case ErrNum    Case 0
            ''''''''''''''''''''''''''''''''''''''''''''
            ' No error occurred.
            ' File is NOT already open by another user.
            '''''''''''''''''''''''''''''''''''''''''''' 
            IsFileOpen = False
        Case 70
            ''''''''''''''''''''''''''''''''''''''''''''
            ' Error number for "Permission Denied."
            ' File is already opened by another user.
            '''''''''''''''''''''''''''''''''''''''''''' 
            IsFileOpen = True
        Case Else
            ''''''''''''''''''''''''''''''''''''''''''''
            ' Another error occurred. Assume open.
            '''''''''''''''''''''''''''''''''''''''''''' 
            IsFileOpen = True End Select

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,412
    for all those wondering what error 53 is - its 'file not found'.

    I've not tested Chip's code but chances are you have missed something in the code you haven't shown.

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    I just tested it (Chip Pearson function) and it gives me False repeatedly, but I have the file open in Notepad???

    I also checked with a modified version of that code from
    http://www.utteraccess.com/forum/Che...&hl=isfileopen
    and it also showed False???

    I also checked another version and its test routine from
    https://exceloffthegrid.com/vba-find-file-already-open/
    and it did not work either.

    When my test file "zeeTrans.txt" was open, all these functions reported IsOpenFile as False???

    One factor I did note was that each of these functions (in vba) came from Excel-oriented sites.

    If someone gets any of these functions to work, please show us the code and the test routine to call the function.


    UPDATE
    :

    I found info at https://stackoverflow.com/questions/...open-by-anyone
    where poster could not get this function to work. He, like me, was using a txt file.

  6. #6
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,722
    Another update:

    Just got an email and within I found this

    (I do want to note that if you use Notepad to open up a file, it will not actually lock the file even though you can clearly see it being used. For some reason, Notepad will open the file and keep it in memory and then only claim a lock on it long enough to save the updates.)
    I opened a jpg, then a png with Irfanview -- in both cases the function said File was not Open.

    However, I did open a word file (.docx) and the function told me it was already open.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Access VBA to check if Excel file is open
    By johnseito in forum Programming
    Replies: 8
    Last Post: 10-30-2017, 06:29 PM
  2. Replies: 6
    Last Post: 09-14-2017, 07:31 AM
  3. Replies: 1
    Last Post: 11-28-2014, 06:56 PM
  4. Replies: 6
    Last Post: 02-07-2013, 03:15 PM
  5. Replies: 2
    Last Post: 02-26-2010, 08:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums