Solved

Check for folder write access

Posted on 2014-02-20
5
568 Views
Last Modified: 2014-02-26
I need my MS Access program to be able to check whether it can delete files in or move files into a particular folder.  Can this be done in VBA?
0
Comment
Question by:Jolio81
  • 2
  • 2
5 Comments
 
LVL 57
ID: 39873830
<< Can this be done in VBA? >>

 Simplest approach is to attempt the operation, then trap the error (error #5).

 You can for example write a small procedure to write a empty file to the directory and see if that fails or not.

Jim.
0
 

Author Comment

by:Jolio81
ID: 39874532
Hi Jim,

I'm using "Shell" to delete and copy files, and it doesn't throw errors when it can't do it. Is there something other than Shell that I can use?

Example:
Shell "cmd /c del ""c:\File.txt"""
0
 
LVL 57
ID: 39874835
No, but you can try the file operations in VBA first (Delete, then Create/delete) and see if it fails or not.

Use

OnError Resume Next
Err = 0
....try something....
If Err<>0 then
   ' We got a problem
EndIf

Jim.
0
 
LVL 20

Accepted Solution

by:
clarkscott earned 500 total points
ID: 39876233
Here's some easy code.
Call this function.  If it comes back true then you're ok.
This function simply creates a txt file - then deletes it.  If you can do this - you're good.

If CanWrite = false then
    '--- we can't write
end if


Function CanWrite() As Boolean
Dim f As Long
On Error GoTo err_hand

f = FreeFile
Open "YourFolderName\test.txt" For Output As #f

''' this is an example:  Open "C:\Stuff\text.txt" for Output as #f

Print #f, "x"
Close f

Kill "YourFolderName\test.txt"
'' this is an example: Kill "C:\Stuff\text.txt"

CanWrite = True
progout:
Exit Sub

err_hand:
    Resume progout
End Function

Scott C
0
 
LVL 20

Expert Comment

by:clarkscott
ID: 39890586
Sometimes easy is the best.  Thanks for the points !!
Good luck with your project.

Scott C
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question