Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Nov 2004
    Location
    Georgia, USA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Closed (Access 2002(10.3409.3501) SP-1)

    Good Afternoon / Morning / Evening to all..

    I have a function that checks to see if a file exist on Disk (just a text file) ... what I need to do is know when the file is closed and not in use by another app.. I've been searching every Access book I have, and have yet to find anything.. Any suggestions would be helpful..

    Thanks

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: File Closed (Access 2002(10.3409.3501) SP-1)

    There is no really good way to do this, and the method you choose depends on the specific conditions. If you can copy the file from one location to another, then it is not in use by any other program. There are API calls that return a handle for a file, but they attempt to open the file in order to determine whether it is in use. If the file is currently being written when the call tries to open it, the file will be truncated, so you need to explain exactly what you're trying to accomplish. In any case, it isn't anything in Access itself, but in Windows.
    Charlotte

  3. #3
    New Lounger
    Join Date
    Nov 2004
    Location
    Georgia, USA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Closed (Access 2002(10.3409.3501) SP-1)

    Hi charlotte,
    Well, thanks to the help from the board here, I have a routine that runs a report via the docmd.OpenReport .. I have my default printer set up as my adobe acrobate creator. hence my problem.. I tried changing the caption of my report name at the on Close event, (this was offered to me by someone on this board, I apoligize that their name escapes me at the moment) Well, this didn't work for me. Adobe would take over and begin creating the PDF file, so when I tried to rename the file in the OnClose event I would get an access denied error.. made sense to me as adobe wasn't finished creating the file when I tried to rename the file. So I decided to try the rename after the docmd object. would run. I got this to work by putting in a counter in a loop, I also got this to work by putting in a timer loop to give Adobe enough time to finish before I would rename my file. (I have 50 different School Reports, that within access would put all the schools in one report. I wanted to run each school seperatly, name the reports rpt_0100, rpt_2050 etc... the numbers being the loacation numbers of the schools - place them in PDF files and email them off)..

    I just don't like the way the counter loop and/or the timer loop I created acts, not to mention if for some reason, the ctr or timer ran out before the PDF was created, the rename would cause the onerr routine to fire. I then tried so set up a condition in the err routine that if the error returned was an invalid access error because the file was still in use, to just ignore it, loop back to the rename until the error condtion stopped, letting me know that the file then would have been closed and completed by Adobe...

    Hope this made sense, it's a zoo in the office today, so if I need to further explain I'd be happy to.. for what it's worth, I'm fairly new to Access, and have pretty much been an old time Cobol/RPG/Clipper programmer for years..

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

    Re: File Closed (Access 2002(10.3409.3501) SP-1)

    You'll find an example function in Determine if a file is in use using VBA in Microsoft Excel (it is not Excel-specific). You can also download and use the free utility WaitForFile from Freeware Utilities by GdP Software. (A google web or newsgroup search for waitforfile will turn up more)

    You will still need some kind of loop to test...

  5. #5
    New Lounger
    Join Date
    Nov 2004
    Location
    Georgia, USA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Closed (Access 2002(10.3409.3501) SP-1)

    Thanky you HansV ...
    I see I was pretty much on the right track, my biggest problem is I wasn't aware of the clear method to the Err object.. I'll play around with this and see if this works.. Looks promising..

  6. #6
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: File Closed (Access 2002(10.3409.3501) SP-1)

    Is there a way to change a report's caption and save the report before you run the report? If so, then there is no need for renaming reports, timer loops etc.

  7. #7
    New Lounger
    Join Date
    Nov 2004
    Location
    Georgia, USA
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: File Closed (Access 2002(10.3409.3501) SP-1)

    Hmmm.. I couldn't agree with you more Pat.. I'm looking at this option as well.. what I found out, is Adobe can be a PAIN in the YOU know where.. LOL... I put the function (that Hans pointed me toward this morning) in my code within a do loop.. Looked like everything was going to be perfect until I noticed that Adobe, opens and closes the file more than once while creating the PDF.. So, upon checking the status of the file to see if it was in use, when Adobe closed it, the loop was ended, the rename would fire, but within that nano second Adobe would have re-opened the file.... Ugh... I will say the function FileAlreadyOpen works perfect though.

  8. #8
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: File Closed (Access 2002(10.3409.3501) SP-1)

    Check out <post#=398062>post 398062</post#>, don't forget to use .label rather than .lable

Posting Permissions

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