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

urjudo

Member
Local time
Today, 00:09
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,
 

Isaac

Lifelong Learner
Local time
Yesterday, 22:09
Joined
Mar 14, 2017
Messages
8,774
check out MkDir
 

urjudo

Member
Local time
Today, 00:09
Joined
Oct 9, 2020
Messages
67
@Issacc,
do you have any example if possible?
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 22:09
Joined
Oct 29, 2018
Messages
21,454
Hi. Just in case it helps, here's a link for you.


And there are some simple examples here.

 

urjudo

Member
Local time
Today, 00:09
Joined
Oct 9, 2020
Messages
67
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.
 

moke123

AWF VIP
Local time
Today, 01:09
Joined
Jan 11, 2013
Messages
3,912
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
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:09
Joined
May 7, 2009
Messages
19,231
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
 

urjudo

Member
Local time
Today, 00:09
Joined
Oct 9, 2020
Messages
67
@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)
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 13:09
Joined
May 7, 2009
Messages
19,231
Its strSubFolder(i)
 

Users who are viewing this thread

Top Bottom