Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect invalid paths for custom backup form and customize msgbox

Status
Not open for further replies.

tekila

Programmer
Apr 18, 2002
150
SG
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
************************************************************



 
I have pasted your entire Backup function with some additions. The code in Red are the additions.
Public Function Backup()
On error goto Backup_Error
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
Backup_Exit:
Exit sub
Backup_Error:
If err = 76 then
MsgBox("Put your custom message here")
me![TextBoxName].setfocus 'returns focus to control with the problem
end if
goto Backup_Exit
End Function

When the err - 76 is found then the message appears and the focus is set back to the control that has the problem. You will have to add some code to the function to keep track of where you are in the code to know which piece of data is incorrect so that you can set the focus to the right control on the form.

Does this help?

Bob Scriver
 
Well, this was what I included in the code instead:]

************************************************************If Not objScript.FolderExists(strActivePath) Then
MsgBox "Active Path specified is invalid." & Chr(13) & "Please check and try again.", vbCritical + vbOKOnly, "Invalid Active Path"
Me!ActivePath.SetFocus
Exit Function
Else
If Not objScript.FolderExists(strBckupPath) Then
MsgBox "Backup Path specified is invalid." & Chr(13) & "Please check and try again.", vbCritical + vbOKOnly, "Invalid Backup Path"
Me!BckupPath.SetFocus
Exit Function
End If
End If
************************************************************

These If...Else... statements only check for valid paths and the drawback is it is assumed that the user knows the path of the database. What if the user "forgets" the path and "thinks" that the database lies in a particular drive (a valid one) and performs a backup? He will then be doing a backup on the wrong source!

I presume there'll be other error messages popping up for different cases and how am I going to take care of that?

Is there a way to allow the user locate the path of the existing Active Database more efficiently and takes care of all run-time errors at the same time?
 
I suppose you could save the legitimate path to the backup folders in a table on the server which can be pulled up at the time of backup. Then you users never have to identify that correct path to the files to be backed up.

Without knowing you system better I can't really say. Normally on backup procedures I take that responsibility out of the end users hands. By storing this info in a table I can control the process completely.

Bob Scriver
 
I guess that's what I want. So how can I go about doing that?
 
I agree, i never let my users have access to backing up the data... if they can back it up, then they must also be able to restore it, other wise it's a waste of time for them to back it up... and if they can restore it, what's stopping them from restoring an old copy, and messing up data integraty... also, if multiple people use the database, then who's to say who has the latest copy of it? and not one that's two months old?? my backup scheem is this...

when my users exit the database the database goes to where the files are stored, makes a new directory for every day, (uses the date to make it new every day...) and copies all the files from the database dir into that new directory... that way it's a little slow for my users on exit... but they don't know what's going on, and i have a fresh copy every day... and i pull it off the server and burn them to a cd about once every two weeks, so i have a backup every day, for almost 3 months now... and that's growing every day...

--Junior JHauge@jmjpc.net
Life is change. To deny change is to deny life.
 
Junior, what if I only want to do a auto backup on the tables since only data in the tables are updated everytime, possible? So whenever someone closes the database, only the tables will be copied over to the auto backup database that contains tables only.

I'm afraid when the database grows to 20 over MB, the transfer of large files over the network will be very slow. That's why I'm thinking of only copying tables.

 
i don't know the code to only backup the tables, but if your just backing up the tables, that's about the same amount of time as copying the backend file... if your concern is that it will get to big, then maybe you should consider a different backup scheam... right now i am working on a design that looks to see if there is any more then one person in the database, and if there is, do nothing... if there is no one else, when you exit then it will copy the files... that way, it faster exiting through the day...

the only concern i have with coping just the tables like you propose, is it is making access work, plus do some file coping, so i would think that would make it slower...

we have talked about a bunch of options with backing up files, let me know how you want to do it, and i'll see if i can help code some thing the way you want it...

--James JHauge@jmjpc.net
Life is change. To deny change is to deny life.
 
Oh, I didn't know that copying tables only does the same amount of work as copying the entire database. So you mean tables occupy similar file size as the database and the copying of tables take just as long as that for the database? What you're currently working on seems relevant to my application. Please keep me informed if you're done with the implementation. I'm kind of interested.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top