Mkdir

  • Thread starter Thread starter Greg
  • Start date Start date
G

Greg

I'm trying to get this function to work, can anyone help

Function Make_Project_Directory(StrDrive, strProject_Directory,
strYear_Directory, strProject_Number)
Dim strProjectPath As String
'Dim result As String
strProjectPath = StrDrive & "\" & strProject_Directory & "\" & _
strYear_Directory & "\" & strProject_Number & "\" & _
"Current_Issue\"
MsgBox Len(Dir(strProjectPath, vbDirectory)) > 0
If Len(Dir(strProjectPath, vbDirectory)) > 0 Then
MsgBox "Directory " & strProjectPath & " already exists"
Else
MkDir strProjectPath
MsgBox "Directory " & strProjectPath & " has been created"
End If
End Function


Public Sub Test()
Make_Project_Directory "C:", "PLD Test", "07-08", "Project"
End Sub


Thanks for any help
 
Greg,
MkDir cannot create multiple levels of directories.
If you need to create multiple levels of directories, call MkDir for each
level.


Jeanette Cunningham
 
Greg said:
I'm trying to get this function to work, can anyone help

Function Make_Project_Directory(StrDrive, strProject_Directory,
strYear_Directory, strProject_Number)
Dim strProjectPath As String
'Dim result As String
strProjectPath = StrDrive & "\" & strProject_Directory & "\" & _
strYear_Directory & "\" & strProject_Number & "\" & _
"Current_Issue\"
MsgBox Len(Dir(strProjectPath, vbDirectory)) > 0
If Len(Dir(strProjectPath, vbDirectory)) > 0 Then
MsgBox "Directory " & strProjectPath & " already exists"
Else
MkDir strProjectPath
MsgBox "Directory " & strProjectPath & " has been created"
End If
End Function


Public Sub Test()
Make_Project_Directory "C:", "PLD Test", "07-08", "Project"
End Sub


Thanks for any help

As Jeanette mentioned, VBA's Mkdir function is limited to one directory
level per call. However, we can roll our own function to accomplish this:

http://www.smccall.demon.co.uk/Strings.htm#CreatePath

Dim ErrNum As Long

ErrNum = CreatePath(strProjectPath)
If ErrNum = 0 Then
MsgBox "Path successfully created."
Else
MsgBox "Path was not created. The error number was " & ErrNum
End If
 
Back
Top