Solved

Check for folder write access

Posted on 2014-02-20
5
561 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now