Validate existance of a directory

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

Hello,

I want to set a startdir variable = "//public/common/%username%" if the
computer has access to the folder otherwise set it equal to "c:\". How can
this be done?

Thank you,

Daniel
 
Dir() can search for folders. The function below provides an example
wrapper.

You will need to pass in a string. To get the username, you might be able to
use:
Environ("username")
or you may prefer to use an API call:
http://www.mvps.org/access/api/api0008.htm

Public Function FolderExists(varPath As Variant) As Boolean
On Error Resume Next
If Len(varPath) > 0& Then
FolderExists = (Len(Dir$(varPath, vbDirectory)) > 0&)
End If
End Function
 
I've tried to use an if statement to verify if the directory exist because
the help file explained that the dir function returned "" if the folder did
not exist

if dir("c:\temp")="" then
msgbox "this directory does not exist"
end if

but I can't seem to get it to work.Could you point out my mistake.

Thankyou

Daniel
 
You're missing the second parameter, vbDirectory:

if dir("c:\temp", vbDirectory)="" then
msgbox "this directory does not exist"
end if
 
Back
Top