I've a custom backup form with three textboxes; ActivePath (Path of current DB), BckupPath (Path of Backup DB) and Name (An optional field if user wants to include a name to the folder of the backup DB, else saved as default name). There are two identical browse buttons next to the textboxes (*Path) that retrieve the folder name that the user selected by calling the standard Browse folder dialog.
The correct procedure is the user clicks the browse buttons and the selected folders' names will be reflected in the respective textboxes. My problem is, if the user tries to enter an invalid path in either textbox, access will display run-time error '76' to indicate that the path is not found. How can I display a customized msgbox to prompt the user that the path he entered is invalid?
This is the backup function that I call when user hits OK button:
************************************************************
Public Function Backup()
Dim strRootPath
Dim strFilename
Dim strDefaultName As String
Dim strActivePath As String
Dim strBckupPath As String
Dim strBckupName As String
Dim objScript
Dim strdate
Dim strMonth
Dim strDay
Dim strYear
Dim strSource
Dim strTarget
strDefaultName = "YieldnDowntimeBckup_"
Set objScript = CreateObject("Scripting.FileSystemObject"
strMonth = DatePart("m", Date)
If Len(strMonth) = 1 Then strMonth = "0" & strMonth
strDay = DatePart("d", Date)
If Len(strDay) = 1 Then strDay = "0" & strDay
strYear = Right(DatePart("yyyy", Date), 4)
strdate = strMonth & strDay & strYear
If IsNull(Me!ActivePath) Or IsNull(Me!BckupPath) Then
MsgBox "Backup Failed - Paths of Databases are not specified.", vbCritical + vbOKOnly, "Path Not Specfied"
Exit Function
Else
strActivePath = Me!ActivePath
strBckupPath = Me!BckupPath
strRootPath = strActivePath & "\"
strSource = strRootPath & "*.*"
If IsNull(Me!Name) Then
strTarget = strBckupPath & "\" & strDefaultName & strdate & "\"
If Not objScript.FolderExists(strTarget) Then
objScript.CreateFolder (strBckupPath & "\" & strDefaultName & strdate & "\"
End If
objScript.CopyFile strSource, strTarget
Set objScript = Nothing
Else
strBckupName = Me!Name
strTarget = strBckupPath & "\" & strBckupName & "_" & strdate & "\"
If Not objScript.FolderExists(strTarget) Then
objScript.CreateFolder (strBckupPath & "\" & strBckupName & "_" & strdate & "\"
End If
objScript.CopyFile strSource, strTarget
Set objScript = Nothing
End If
End If
End Function
************************************************************
The correct procedure is the user clicks the browse buttons and the selected folders' names will be reflected in the respective textboxes. My problem is, if the user tries to enter an invalid path in either textbox, access will display run-time error '76' to indicate that the path is not found. How can I display a customized msgbox to prompt the user that the path he entered is invalid?
This is the backup function that I call when user hits OK button:
************************************************************
Public Function Backup()
Dim strRootPath
Dim strFilename
Dim strDefaultName As String
Dim strActivePath As String
Dim strBckupPath As String
Dim strBckupName As String
Dim objScript
Dim strdate
Dim strMonth
Dim strDay
Dim strYear
Dim strSource
Dim strTarget
strDefaultName = "YieldnDowntimeBckup_"
Set objScript = CreateObject("Scripting.FileSystemObject"
strMonth = DatePart("m", Date)
If Len(strMonth) = 1 Then strMonth = "0" & strMonth
strDay = DatePart("d", Date)
If Len(strDay) = 1 Then strDay = "0" & strDay
strYear = Right(DatePart("yyyy", Date), 4)
strdate = strMonth & strDay & strYear
If IsNull(Me!ActivePath) Or IsNull(Me!BckupPath) Then
MsgBox "Backup Failed - Paths of Databases are not specified.", vbCritical + vbOKOnly, "Path Not Specfied"
Exit Function
Else
strActivePath = Me!ActivePath
strBckupPath = Me!BckupPath
strRootPath = strActivePath & "\"
strSource = strRootPath & "*.*"
If IsNull(Me!Name) Then
strTarget = strBckupPath & "\" & strDefaultName & strdate & "\"
If Not objScript.FolderExists(strTarget) Then
objScript.CreateFolder (strBckupPath & "\" & strDefaultName & strdate & "\"
End If
objScript.CopyFile strSource, strTarget
Set objScript = Nothing
Else
strBckupName = Me!Name
strTarget = strBckupPath & "\" & strBckupName & "_" & strdate & "\"
If Not objScript.FolderExists(strTarget) Then
objScript.CreateFolder (strBckupPath & "\" & strBckupName & "_" & strdate & "\"
End If
objScript.CopyFile strSource, strTarget
Set objScript = Nothing
End If
End If
End Function
************************************************************