Creating a series of folders if none exists.

D

Don

I have a form that displays records for sale units. On that form there
is a button that, when clicked, opens a folder (e.g. 07-19) that
contains four related subfolders (e.g. Documents, Pictures, Maps,
Miscellaneous). The user can then open the tools related to that sales
record from the form. The hierarchy for these folders is
FY07>07-19>Documents.

I have coded the button to edit the hyperlink address using the
SaleUnitID (e.g. 07-19) field where the first two characters represent
the fiscal year and the last two characters represent the sale unit.

Like so:

ViewFilesLink.HyperlinkAddress = "\\Druma701va16100\forestry\Sales
Data\FY" & Left(SaleUnitId, 2) & "\" & [SaleUnitId] & "\"

However, if those folders do not exist, the button cannot find those
folders. In that case, I would like another button that, when clicked,
creates the fiscal year folder (e.g. FY07), the sale unit folder (e.g.
07-19) and the four subfolders (e.g. Documents, Pictures, Maps,
Miscellaneous) by using the SaleUnitID of the current record. If the
fiscal year folder (e.g. FY07) does exist, I would like the button to
create only the sale unit folder (e.g. 07-19) and the four subfolders
(e.g. Documents, Pictures, Maps, Miscellaneous).

I think I should be using Mkdir but I am unsure exactly how to code
these circumstances.

Any help would be greatly appreciated. Thanks in advance.
 
D

Don

Sorry. It seems like I often post just before I find what I need. Using
another post, I was able to modify the code to make it work for me.
Here it is:

Private Sub CreateNewFoldersButton_Click()
On Error GoTo Err_Hand
aaa = "\\Druma701va16100\forestry\Sales Data\FY" & Left(SaleUnitId, 2)
bbb = aaa & "\" & [SaleUnitId] & "\"
ccc = bbb & "Coverage Data"
ddd = bbb & "Documents"
eee = bbb & "Maps"
fff = bbb & "Prescription Data"

If Len(Dir(aaa, vbDirectory)) = 0 Then
MkDir ([aaa])
End If

If Len(Dir(bbb, vbDirectory)) = 0 Then
MkDir ([bbb])
End If

If Len(Dir(ccc, vbDirectory)) = 0 Then
MkDir ([ccc])
End If

If Len(Dir(ddd, vbDirectory)) = 0 Then
MkDir ([ddd])
End If

If Len(Dir(eee, vbDirectory)) = 0 Then
MkDir ([eee])
End If

If Len(Dir(fff, vbDirectory)) = 0 Then
MkDir ([fff])
End If

Exit_Here:
Exit Sub
Err_Hand:
On Error Resume Next
Resume Exit_Here
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top