Solved

Check for folder write access

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 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

22 Experts available now in Live!

Get 1:1 Help Now