Private Sub Command8_Click()
Dim lngRetval As Long
Dim strName As String, strFile As String, strFileName As String
strName = Me.SiteName ' then name of the text box that holds your site
strFile = "c:\AsbestosSurveyPro\data\" ' default file location
strFileName = strFile & strName ' the full directory name
If Dir(strFileName, vbDirectory) <> "" Then
' Directory exists, insert your file output code here
Else
' Directory doesn't exist
' Prompt user if he wants it to be created
lngRetval = MsgBox("Create path?", vbYesNo, "Path doesn't exist")
If lngRetval = 6 Then
' User asked to create dir, so create it.
' Well, the nested directory doesn't exist, but need
' to check if the vbtemp exists to avoid similar error
If Dir(strFile, vbDirectory) <> "" Then
' Just create the sub-directory
MkDir (strFileName)
Else
' Create main and then sub-dir
MkDir (strFile)
MkDir (strFileName)
End If
' Check if it got created
If Dir(strFileName, vbDirectory) <> "" Then
' Let user know it was success
MsgBox ("Path created succesfully.")
Else
' Let user know it was failure
MsgBox ("Error creating path.")
End If
Else
' User asked not to create dir
MsgBox ("Path was not created.")
End If
End If
Dim strDocName As String
strDocName = "Survey"
DoCmd.OpenForm strDocName, , , , acFormAdd
End Sub