Solved Create folder and subfolders in OneDrive from a Form (1 Viewer)

urjudo

Member
Local time
Today, 05:45
Joined
Oct 9, 2020
Messages
67
Hello,
Is possible to program a button in a form to create folder and subfolders. I want to have the Button on the Main form that has the Parties's name and the case#. what I would like to do is create a folder named C1234567_Doe, John vs. Doe, Jane also create few subfolders (named Order, Billings, Appointments) inside this folder at the same time . Any help will be great appreciate.

Thank you,
 
@Issacc,
do you have any example if possible?
 
Hi. Just in case it helps, here's a link for you.


And there are some simple examples here.

 
The code below is create a main folder, What I should changed or added to the code so it can create 3 sub folders named "Orders" and "Billings" and "Appointments"

Code:
Private Sub cmdCreateFolder_Click()
Dim fs As Object
Dim builtpath As String
Set fs = CreateObject("Scripting.FileSystemObject")

builtpath = Environ("UserProfile") & "\Documents\CaseDoc\"

If fs.FolderExists(builtpath) = False Then
    fs.CreateFolder (builtpath)
End If

builtpath = builtpath & Trim(Me.CPCASENUM.Value) & "_" & Trim(Me.PLName.Value) & " vs. " & Trim(Me.CLName.Value) & "\"

If fs.FolderExists(builtpath) Then
    MsgBox "The folder exists"
Else
    fs.CreateFolder (builtpath)
    MsgBox "Folder created!"
End If


End Sub

Thank you for your time.
 
The code below is create a main folder, What I should changed or added to the code so it can create 3 sub folders named "Orders" and "Billings" and "Appointments"

Code:
Private Sub cmdCreateFolder_Click()
Dim fs As Object
Dim builtpath As String
Set fs = CreateObject("Scripting.FileSystemObject")

builtpath = Environ("UserProfile") & "\Documents\CaseDoc\"

If fs.FolderExists(builtpath) = False Then
    fs.CreateFolder (builtpath)
End If

builtpath = builtpath & Trim(Me.CPCASENUM.Value) & "_" & Trim(Me.PLName.Value) & " vs. " & Trim(Me.CLName.Value) & "\"

If fs.FolderExists(builtpath) Then
    MsgBox "The folder exists"
Else
    fs.CreateFolder (builtpath)
    MsgBox "Folder created!"
End If


End Sub

Thank you for your time.
You can simply concatenate those folders onto your builtpath

Code:
If fs.FolderExists(builtpath) Then
        MsgBox "The folder exists"
    Else
        fs.CreateFolder (builtpath)


        fs.CreateFolder (builtpath & "Orders")


        fs.CreateFolder (builtpath & "Billings")


        fs.CreateFolder (builtpath & "Appointments")


        MsgBox "Folder created!"


    End If
 
Code:
Private Sub cmdCreateFolder_Click()
    Dim builtpath As String
    Dim strSubFolder(1 To 3) As String
    Dim var As Variant
    Dim strFolder As String
    Dim i As Integer
    strSubFolder(1) = "Orders"
    strSubFolder(2) = "Billings"
    strSubFolder(3) = "Appointments"
    
    builtpath = Environ("UserProfile") & "\Documents\CaseDoc\"
    builtpath = builtpath & Trim(Me.CPCASENUM.Value) & "_" & Trim(Me.PLName.Value) & " vs. " & Trim(Me.CLName.Value) & "\"
    
    'split builtpath
    var = Split(builtpath, "\")
    'create the main folder
    'ignoring error when the folder already exists
    On Error Resume Next
    For i = 0 To UBound(var)
        If Len(Trim$(var(i) & "")) > 0 Then
            strFolder = strFolder & var(i)
            VBA.MkDir strFolder
            strFolder = strFolder & "\"
        End If
    Next
    'create the subfolders
    For i = 1 To 3
        strFolder = builtpath & "\" & strFolder(i)
        VBA.MkDir strFolder
    Next
End Sub
 
@moke123 ,
Thanks! that works!

@arnelgp ,
Thanks! I did try your code as well. the only thing is I got an error on strFolder = builtpath & "\" & strFolder(i), the error message was "Complie error, expected array on the stFolder(i)
 
Its strSubFolder(i)
 

Users who are viewing this thread

Back
Top Bottom