Creating a folder in Windows Explorer

gsrajan

Registered User.
Local time
Today, 06:32
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.
 
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
 
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
 
Code:
MkDir "C:\Users\Joel\Documents\" & Me.txtFolderName
                              ^
                              |
You need a backslash to separate the path.
 
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:\\ ?
 
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
 
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.
 
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

Back
Top Bottom