Solved

Check for folder write access

Posted on 2014-02-20
5
575 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 58
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 58
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

630 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