Difference between revisions of "Microsoft Access modFso"
Jump to navigation
Jump to search
(Created page with '=== assertPath === <syntaxhighlight lang="vb"> Sub assertPath(strPath) Dim fso As FileSystemObject Dim blnFirst As Boolean blnFirst = True Set fso = New File...') |
|||
Line 1: | Line 1: | ||
=== assertPath === | === assertPath === | ||
<syntaxhighlight lang="vb"> | <syntaxhighlight lang="vb"> | ||
− | Sub assertPath(strPath) | + | Public Sub assertPath(strPath) |
Dim fso As FileSystemObject | Dim fso As FileSystemObject | ||
Dim blnFirst As Boolean | Dim blnFirst As Boolean |
Revision as of 14:02, 1 July 2010
assertPath
Public Sub assertPath(strPath)
Dim fso As FileSystemObject
Dim blnFirst As Boolean
blnFirst = True
Set fso = New FileSystemObject
With fso
If Not .FolderExists(strPath) Then
On Error GoTo handleCreateFolderError
.CreateFolder strPath
On Error GoTo 0
End If
End With
Exit Sub
handleCreateFolderError:
If Err.Number = 76 And blnFirst Then
Debug.Print strPath & " not found - trying to create parent ..."
assurePath fso.GetParentFolderName(strPath)
blnFirst = False
Resume
Else
MsgBox "The path '" & strPath & "' could not be found, nor created.", vbExclamation + vbOKOnly
End If
End Sub