ACCESS denied error for VBA created folders.

L

lavanya

I am using access 2000.
I have created a set of nested subdirectories from my VBA
code using createfolder method.
When I try to delete the directories from windows XP , it
gives me the message
ACCESS denied. Check if the disk is full or write
protected.
However if I exit my database completely, the delete goes
through fine.
What could I be doing wrong. I have tried setting all the
filesystem objects in my code to nothing once they are
done being used.

any help will be appreciated.
 
D

Douglas J. Steele

What CreateFolder method? Access doesn't have any such method, so you must
be using FSO or some other approach. Better show us the code you're using so
that we can comment.

There's a built-in MkDir statement in VBA that will do this for you.
 
S

Steve

I've had this problem in VB. I solved it using SetAttr (set attribute)...like thi
Call SetAttr(myFile, vbArchive
Kill (myFile)
 
T

thriveni

yes, I do use the fso.CreateFolder.
are there any advantages of using the mkdir compared to
the existing method I use ?
and here is the code:

Function check_path(image_path As String)

Dim parent_folder As String
Dim fs As FileSystemObject


last_delim_pos = InStrRev(image_path, "\")
last_dir = Mid(image_path, last_delim_pos)
Set fs = CreateObject("Scripting.FileSystemObject")
parent_folder = fs.GetParentFolderName(image_path)

If fs.FolderExists(parent_folder) Then
'Debug.Print "folder exists"
fs.CreateFolder (image_path)
Else
check_path(parent_folder) 'recursion
fs.CreateFolder (image_path)
End If
Set fs = Nothing
check_path_exists = True
End Function
 
S

Steve

I would think that you would also need to empty the directory before removing it. Therefore, kill all the files in the directory, and perform a rmdir. Do a setAttr too.
 
C

Cheryl Fischer

You can use FSO's DeleteFolder method (with the Force argument set to True
if the ReadOnly attribute has been set) to delete folders.
 
T

thriveni

Yes I am using the fso.createfolder method.
Is there any advantage using the mkdir ?
anyway here is the code that is creating the directories

Function check_path(image_path As String)
Dim parent_folder As String
Dim fs As FileSystemObject

last_delim_pos = InStrRev(image_path, "\")
last_dir = Mid(image_path, last_delim_pos)
Set fs = CreateObject("Scripting.FileSystemObject")
parent_folder = fs.GetParentFolderName(image_path)

If fs.FolderExists(parent_folder) Then
fs.CreateFolder (image_path)
Else
check_path (parent_folder) 'recursion here
fs.CreateFolder (image_path)
End If
Set fs = Nothing
check_path_exists = True
End Function

thanks for any help
 
G

Guest

Thanku for your response. As Cheryl has suggested, I will
try to see if deletefolder with force will work in my case
since it involves fewer steps, and otherwise will try
Steve's method of SEttAttribute and then removing all
files and then the folders.
-----Original Message-----
I would think that you would also need to empty the
directory before removing it. Therefore, kill all the
files in the directory, and perform a rmdir. Do a setAttr
too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top