MS Access – MakeFolder Routine

In Access you can automatically create a folder if it doesn’t exist by using the code below. The two supporting functions are also shown below.

Dim strPath As String
strPath = “C:\Users\”
If Not FolderExists(strPath) Then If MsgBox(“Path ” & strPath & ” does not exist. Create?”, vbYesNo) = vbYes Then MakeFolder (strPath)

Public Function FolderExists(strPath As String) As Boolean
FolderExists = ((GetAttr(strPath) And vbDirectory) = vbDirectory)
End Function

Public Sub MakeFolder(strPath As String)
x = “”
If Dir(strPath, vbDirectory) > vbNullString Then Exit Sub
arr1 = Split(strPath, “\”)
For Each Folder In arr1
x = x & Folder
If Not InStr(Folder, “:”) = 2 Then MkDir x
x = x & “\”
End Sub