Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    WAVP375 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171

    Attempt to delete a file

    I am attempting to delete a file in a folder without success using the following code:
    Sub DeleteFile(DocPath As String)
    MsgBox DocPath
    If Len(Dir$(DocPath)) > 0 Then


    SetAttr DocPath, vbNormal
    Kill DocPath
    End If
    End Sub
    Contents of DocPath is: D:\COA Raw Documents\2020-09-18_141944.pdf
    I am administrator.

    I have attempted many variations to the sub with the same result; Error 70, Permission Denied.
    Where do I go next?

    Thanks

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Sounds like system permissions prevent deleting this file. It could be folder permission setting or specifically this file.

    Can you delete file manually? Could be programmatic delete is blocked. I ran into situation where could not even programmatically copy file when IT set up new computers.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    not sure why you are using Dir$ rather than just Dir or why you are setting an attribute - neither are normally required to do what you want to do. The use of $ with Dir or other functions is a throwback to BASIC days - ancient history

    And to be sure - rather than msgboxing the input - try msgboxing the output - MsgBox Dir$(DocPath)

    Also which line is causing the error - SetAttr or Kill?

  4. #4
    WAVP375 is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    The error occurs with the kill command.

    I thought administrator gave me all the permission required. How can I change the permissions to allow this deletion?
    I will be deleting all files in the folder one at a time after working on each one and saving it in another folder.

    Thanks

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    regret I don't know. As per June's suggestion in post#2 - can you delete manually?

  6. #6
    WAVP375 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    It doesnt seem like a a problem at the folder or file level since I can delete it manually.
    Is there some kind of permissions higher or other than administrator?

  7. #7
    WAVP375 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    I have found some permissions associated with the folderr and file level which I have changed to 'Full Control' but makes no differenc either.
    The file is a read only file, though I dont know why. It is created from a pdf scan of a hard document.

  8. #8
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    read only should not matter from the perspective of deleting - just means you can't edit it.

    Only other thought is the file is already open - you cannot delete it if already open. Perhaps you have other code that has opened it, but not closed it?

  9. #9
    WAVP375 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    I am certain that the file is open but sincw it was opened dir() I cant close it.I assume the statemnt dir() actually opens the file and reads the first record. I havent found any way to the open the subsequent records if Dir() only reads the next record which is the first one.

  10. #10
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    I assume the statemnt dir() actually opens the file and reads the first record
    no, it just tells you the file exists or not.

    You said
    I will be deleting all files in the folder one at a time after working on each one and saving it in another folder.
    which makes me think you have opened the file to work on it - saving it in a different folder doesn't necessarily close it in the original folder

  11. #11
    WAVP375 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    Yes what I'm doing is altering the filename with data that will be used for document lookup in another procedure. Since I didnot issue an open command based on others opinion I cant close. However if the dir() only tells me if its there is the file actually open?
    It seems like there should be a way to delete a file under any circumstance.

    I appreciate you sticking with me to find a resolution.

  12. #12
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    You've lost me - now you are altering a file name? thought you were altering the contents of a file, which means opening it.

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,816
    Did you read post 2?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    WAVP375 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2015
    Location
    Dayton Ohio
    Posts
    171
    Ajax, I have been able to make the kill command work as long as I have a msgbox immediatly in front of the kill. I thought it might be a timing issue but a timer with any amount of time does not get it done. Any msgbox seems to work.
    Any thoughts on what might be the cause?

    Thanks

  15. #15
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,397
    what do you mean by a timer? Pause?

    Have you tried using DoEvents?

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 10-14-2019, 04:28 AM
  2. LACCDB file won't delete
    By ranman256 in forum Access
    Replies: 4
    Last Post: 05-17-2016, 08:10 AM
  3. Update and delete from linked txt file?
    By gec5741 in forum Database Design
    Replies: 1
    Last Post: 04-26-2013, 05:21 PM
  4. VBA code to delete the 2nd line in a csv file
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 03-02-2013, 02:16 AM
  5. How to tell if a file exists and then delete it
    By orcinus in forum Programming
    Replies: 3
    Last Post: 05-17-2010, 05:15 PM

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