MkDir won't create a directory and sub directory at the same time

  • Thread starter pubdude2003 via AccessMonster.com
  • Start date
P

pubdude2003 via AccessMonster.com

For instances where my FolderPath value is "C:\MyQuotation\Jan" it won't
create the directory. Is there something I can do to correct the code?

Dim Path As String

If Not IsNull(DLookup("FolderPath", "UserPass")) Then
Path = (DLookup("FolderPath", "UserPass"))
End If

If Dir(Path, vbDirectory) = "" Then
MkDir Path
End If

Dim strLinkPath As String
Dim objShell As Object

If Path = "" Then
Set objShell = CreateObject("WScript.Shell")
strLinkPath = objShell.SpecialFolders("MyDocuments")
Else
strLinkPath = Path
End If
 
O

OfficeDev18 via AccessMonster.com

Sorry, but "Path" is a valid Access property, otherwise called a "reserved
word." You cannot use reserved words as variable names. Change all instances
of the standalone word "Path" and try your program again.

Sam
 
P

pubdude2003 via AccessMonster.com

Thanks Dev, didn't know that, although the code did work for single dir
creation.

At any rate here is the code for multiple dir


Dim strPath As String
Dim aFolders() As String
Dim I As Integer

If Not IsNull(DLookup("FolderPath", "UserPass")) Then
strPath = (DLookup("FolderPath", "UserPass"))
End If

If Dir(strPath, vbDirectory) = "" Then

If Len(strPath) = 0 Then
Err.Raise 5
Exit Sub
End If

aFolders = Split(strPath, "\")
strPath = vbNullString

For I = LBound(aFolders) To UBound(aFolders)
strPath = strPath & aFolders(I)
If Len(Dir(strPath, vbDirectory)) = 0 Then
MkDir strPath
End If
strPath = strPath & "\"
Next I

End If
 
P

pubdude2003 via AccessMonster.com

Thanks Dev, didn't know that, although the code did work for single dir
creation.

At any rate here is the code for multiple dir


Dim strPath As String
Dim aFolders() As String
Dim I As Integer

If Not IsNull(DLookup("FolderPath", "UserPass")) Then
strPath = (DLookup("FolderPath", "UserPass"))
End If

If Dir(strPath, vbDirectory) = "" Then

If Len(strPath) = 0 Then
Err.Raise 5
Exit Sub
End If

aFolders = Split(strPath, "\")
strPath = vbNullString

For I = LBound(aFolders) To UBound(aFolders)
strPath = strPath & aFolders(I)
If Len(Dir(strPath, vbDirectory)) = 0 Then
MkDir strPath
End If
strPath = strPath & "\"
Next I

End If
 

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