Creating a folder in Windows Explorer (1 Viewer)

gsrajan

Registered User.
Local time
Today, 12:45
Joined
Apr 22, 2014
Messages
227
Please let me know how to create a folder in Windows Explorer from access form command button if possible. My folder name will be in a text box named txtFolderName. The path will be: s:\\cases\2020

Thanks for your help. Let me take this moment to thank all the genius in this forum who are always helpful to me. Thank you.
 

cheekybuddha

AWF VIP
Local time
Today, 17:45
Joined
Jul 21, 2014
Messages
2,280
Something like:
Code:
Private Sub cmdNewFolder_Click()

  If Len(Me.txtFolderName & vbNullString) Then
    MkDir "s:\\cases\2020\" & Me.txtFolderName
  End If

End Sub

hth,

d
 

gsrajan

Registered User.
Local time
Today, 12:45
Joined
Apr 22, 2014
Messages
227
Thank you. I am getting error: Run time error: 75
Path/File access error.

I tried even in the local folder:

Private Sub Command2_Click()
If Len(Text0 & vbNullString) Then
MkDir "C:\Users\Joel\Documents" & Me.txtFolderName

End If
End Sub
 

cheekybuddha

AWF VIP
Local time
Today, 17:45
Joined
Jul 21, 2014
Messages
2,280
Code:
MkDir "C:\Users\Joel\Documents\" & Me.txtFolderName
                              ^
                              |
You need a backslash to separate the path.
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:45
Joined
Sep 21, 2011
Messages
14,324
Thank you. I am getting error: Run time error: 75
Path/File access error.

I tried even in the local folder:

Private Sub Command2_Click()
If Len(Text0 & vbNullString) Then
MkDir "C:\Users\Joel\Documents" & Me.txtFolderName

End If
End Sub
PMFJI
Wouldn't you need to check the actual length?

Plus a path would not start with s:\\ ?
 

jdraw

Super Moderator
Staff member
Local time
Today, 12:45
Joined
Jan 23, 2006
Messages
15,379
I'm quite sure that MkDir only allows you to build/create 1 level of folder at a time.
So,if you have C:\users\Bob, then you could add MyTests to give
C:\users\Bob\MyTests

but if you're trying to create C:\Tests\March\2020 you would need to create in steps.

C:\Tests
C:\Tests\March
C:\Tests\March\2020
 

gsrajan

Registered User.
Local time
Today, 12:45
Joined
Apr 22, 2014
Messages
227
Thank you very much. Thank you for your patience. As Cheekybuddha said, I added a backslash, which was missing. It works now. Thank you all for your time and help.
 

cheekybuddha

AWF VIP
Local time
Today, 17:45
Joined
Jul 21, 2014
Messages
2,280
I'm quite sure that MkDir only allows you to build/create 1 level of folder at a time.
Very good point! 👍

@gsrajan
You can maybe adjust your code like:
Code:
Private Sub cmdNewFolder_Click()

  Dim arrFldrs As Variant, i As Integer, strPath As String
  Const BASE_PATH As String = "C:\Users\Joel\Documents\"

  If Len(Me.txtFolderName & vbNullString) Then
    arrFldrs = Split(Me.txtFolderName, "\")
    For i = 0 To UBound(arrFldrs)
      strPath = strPath & "\" & arrFldrs(i)
      If Len(Dir(BASE_PATH & strPath, vbDirectory)) = 0 Then
        MkDir BASE_PATH & strPath
      End If
    Next i
  End If

End Sub

hth,

d
 

Users who are viewing this thread

Top Bottom