Solved

Check for folder write access

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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Archiving Access table older than 6 months 9 38
Dlookup MSACCESS 5 25
Why get error when delete all records on a sub-form 2 15
IIF help, YN field 7 22
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

776 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