0

VBA - Access

I'm using fso.DeleteFolder to delete a folder on a server that an earlier function in the same Access DB created. The fso.DeleteFolder code runs without error and running fso.FolderExists after shows the folder no longer exists (prior to the delete, fso.FolderExists stated that the folder did exist).

However the folder is still listed in File Explorer on the server. Refreshing does no good. When double-clicking the folder on the server, I get an error stating that the folder is not accessible and access denied (prior to the delete, the folder was normal).

The folder may or may not have subfolders and/or files - but I do not think that is important because if I run the create / delete processes over again using a different folder name, the issue repeats - EXCEPT the prior folder is now no longer listed in File Explorer (truly deleted now as God intended), replaced with the new folder that was supposed to be deleted with the same double-click error and so on.

I kill my fso object at the end of the function, I believe the same issue also happens with KILL instead of fso.

Any help/thoughts would be appreciated.

Scotty B
  • 3
  • 5
  • How about this: http://stackoverflow.com/questions/28506725/vba-batch-script-refresh-folder – Absinthe Mar 21 '17 at 22:08
  • I've gone up levels, etc in explorer and gone back to it and the "deleted" folder is still there. I've manually refreshed the folder and it did not work. – Scotty B Mar 21 '17 at 22:38
  • Also after a while - maybe an hour or so, it resolves itself and the folder is not longer listed in Explorer. Perhaps this is a locking issue after the delete by fso? – Scotty B Mar 21 '17 at 22:43
  • Yeah maybe so. I honestly dont know. Maybe some Google-Fu or other SO users will reveal the answer. I'll watch this question. – Absinthe Mar 21 '17 at 22:45
  • This sounds more like a file cache configuration issue rather than a VBA issue. You might want to ask over on [superuser](https://superuser.com/). – Comintern Mar 21 '17 at 22:51
  • Try moving (renaming) the folder and then deleting it using fso. My thought process is if you can't move it then some other process has it open; but Comintern is probably right --- the server might just be displaying to you the wrong thing. – Cody G Mar 22 '17 at 12:17

1 Answers1

1

Just encountered that problem!

For some reason deleting a directory with VBA leaves that lingering "lock" on the deleted file UNTIL it performs another directory type action then it flushes the "lock" If you were to delete three directories in one script you would likely find that the only "failed" delete action would be on the last directory deleted.

Performing a "directory read" type action within the script after the RmDir action works for me. Try something like this...

If Dir("yourpath") = "" Then MkDir "yourpath"