filtrationproducts
asked on
Create Folder in Visual Basic
I currently use the code inside a visual basic application to create the folder in the format below;
V:\7.3\F730000_Hyperlinks\ PMR-1_Docu mentation\
I would like it to create the Documentation folder inside the PMR-1 instead like this;
V:\7.3\F730000_Hyperlinks\ PMR-1\Docu mentation\
Is this possible? I attached the code I use now below.
V:\7.3\F730000_Hyperlinks\
I would like it to create the Documentation folder inside the PMR-1 instead like this;
V:\7.3\F730000_Hyperlinks\
Is this possible? I attached the code I use now below.
Private Sub Command99_Click()
Dim strPath As String
Dim strFolderName As String
Dim FolderName As String
strPath = "V:\7.3\F730000_Hyperlinks\"
strFolderName = "PMR-" & Me.ID_PMR.Value & "_CustomerCommunication"
FolderName = (strPath & strFolderName)
If Len(Dir(FolderName, vbDirectory)) = 0 Then
MkDir FolderName
Call Shell("explorer.exe " & FolderName, 1)
Else
Call Shell("explorer.exe " & FolderName, 1)
End If
End Sub
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
VBRocks,
That also gives me an error on the MkDir FolderName line
That also gives me an error on the MkDir FolderName line
Private Sub Command98_Click()
Dim strPath As String
Dim strFolderName As String
Dim FolderName As String
strPath = "V:\7.3\F730000_Hyperlinks\"
strFolderName = "PMR-" & Me.ID_PMR.Value & "\Documentation\"
FolderName = (strPath & strFolderName)
If Len(Dir(FolderName, vbDirectory)) = 0 Then
MkDir FolderName
Call Shell("explorer.exe " & FolderName, 1)
Else
Call Shell("explorer.exe " & FolderName, 1)
End If
End Sub
What kind of error are you getting? It worked perfect for me.
ASKER
Very Strange... I tried it again after closing Access and reopening Access and it started working properly.
Thanks!
Thanks!
ASKER
Now its not working again and I havent changed anything. All I did was close and reopen it and it will not create the folder. If the folder exists already it will open but if it doesnt exist it will error on the MkDir command saying "path not found"
Do all of the parent folders exist?
For example,
"V:\7.3" must exist before you can try to create "V:\7.3\F730000_Hyperlinks
And... "V:\7.3\F730000_Hyperlinks
"V:\7.3\F730000_Hyperlinks
ASKER
The only folder that exists is "V:\7.3\F730000_Hyperlinks \"
Everything after that needs to be created by the code... \PMR-#\DOCUMENTATION\
So with that code I am using now it is creating two folders \PMR-1 and \Documentation\ within that folder
Everything after that needs to be created by the code... \PMR-#\DOCUMENTATION\
So with that code I am using now it is creating two folders \PMR-1 and \Documentation\ within that folder
So create each one separately:
MkDir "V:\7.3\F730000_Hyperlinks \PMR-1"
MkDir "V:\7.3\F730000_Hyperlinks \PMR-1\Doc umentation "
MkDir "V:\7.3\F730000_Hyperlinks
MkDir "V:\7.3\F730000_Hyperlinks
ASKER
I got it to work.
Dim strPath As String
Dim strPath2 As String
Dim strFolderName As String
Dim FolderName As String
Dim FolderName2 As String
strPath = "V:\7.3\F730000_Hyperlinks\"
strFolderName = "PMR-" & Me.ID_PMR.Value
FolderName = (strPath & strFolderName)
strPath2 = "V:\7.3\F730000_Hyperlinks\" & strFolderName & "\Documentation"
strFolderName2 = "\Documentation\"
FolderName2 = (FolderName & strFolderName2)
If Len(Dir(FolderName, vbDirectory)) = 0 Then
MkDir FolderName
End If
If Len(Dir(FolderName2, vbDirectory)) = 0 Then
MkDir FolderName2
Call Shell("explorer.exe " & FolderName2, 1)
Else
Call Shell("explorer.exe " & FolderName2, 1)
End If
Cool! Great job!
ASKER
MkDir FolderName