don't understand MkDir in Windoze, get runtime error

G

Guest

I want to create the "c:\test" directory if it isn't already created. If it
is created I want it to do nothing. So the first time I run my sub procedure
it does create the directory but the second time I run it, it does not do
nothing it gives me a runtime error. "Path/file access error on the MkDir
line. So I guess I need a better test than the one I have? Can you help?
tia,

If Dir(STR_DIRECTORY_PATH) = "" Then
MkDir STR_DIRECTORY_PATH

Else
End If
 
A

Albert D. Kallal

That is because the directory already exists.....

so, try:

? dir("c:\oem",vbDirectory) = "" then


You need to add the keyword vbDirectory.

In fact you just made me solve a long time bug in my software!!!

Further, you should NOT have the trailing "\".

eg:
? dir("c:\oem\",vbDirectory) = "" then

However, the above actually *will* work in that you get a "." for the dir
name....


-
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
(e-mail address removed)
 
L

Larry Linson

Janis said:
I want to create the "c:\test" directory if it isn't already created. If
it
is created I want it to do nothing. So the first time I run my sub
procedure
it does create the directory but the second time I run it, it does not do
nothing it gives me a runtime error. "Path/file access error on the MkDir
line. So I guess I need a better test than the one I have? Can you help?
tia,

If Dir(STR_DIRECTORY_PATH) = "" Then
MkDir STR_DIRECTORY_PATH

Else
End If

The following worked for me, on Win XP SP 3, MS Access 2002 SP 3. It didn't
find, but then created the folder as specified in the Constant. You didn't
show us the contents of your constant... I chose to specify the full path,
starting with the drive letter, but Access and VBA are reasonably flexible.
It's just you may not realize what the current path is if you leave it up to
the system.

Const STR_DIRECTORY_PATH = "C:\~~~ATESTFOLDER"

If Dir(STR_DIRECTORY_PATH) = "" Then
MkDir STR_DIRECTORY_PATH
End If

You are asking questions about using VBA in Access here, aren't you? It
appeared from your other post that perhaps you were using VBA in Excel
itself. This newsgroup is for discussion of and questions and answers about
Microsoft Access database software.

If it's not a matter of the path being specified as you want, then you
probably need to determine if you have permissions / authority to create a
folder in the specified path. Unless appropriate permissions have been
specifically granted to you, you might well NOT have the authority to create
a folder on a server drive.

Larry Linson
Microsoft Access MVP
 

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