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!

Automating the back up process

Status
Not open for further replies.

fockewulf190

Technical User
Jan 2, 2003
23
US
I would like to make a button on a form (or toolbar) that will open a drive box and allow the user to save/backup the database they are working on to the path of their choosing. Any help would be appreciated

Thanks
 
Probably the easiers way for you to do this is to create a macro attached to a button using the SendKeys commands. This is very easy. for instance...

your macro would have

SendKeys

at the bottom the keys are %F (This means ALT+F)
Wait = NO

SendKeys
Keys are A
Wait=Yes

that will do it....

so you will have on your macro

SendKeys
SendKeys

Thats it!
 
CMoore thanks for the reply .... I tried the SendKeys macro you suggested but that just allows the user to save the form that's open and not the entire database. I would like a way to save or back-up the entire database the individual is working in from the click of a button.

Thanks
 
I am trying to use this same senario but when the button is linked to the macro (Which I defined as above) nothing happens.
Please advise.
Thank you.
Dré
 
Here's a routine that relies upon a path as an optional parameter or creates a folder and backup in \backup where the existing backend resides. This is built for a split db, but it doesn't take much to make it work for a unified db:

[tt]Public Function MakeBackupCopy(Optional v_Context As String, _
Optional v_BackupPath As String) As Boolean

On Error GoTo Error_MakeBackupCopy

Dim strBEFile As String
Dim strCrntFile As String
Dim strBEPath As String

Dim strTargetFolderPath As String
Dim strTargetFile As String

Dim FSO As New FileSystemObject

Dim File As File
Dim Tdf As DAO.TableDef

'Prime function
MakeBackupCopy = False

'Use existing FE filename + date tag for TargetFile
strTargetFile = CurrentProject.Name

'Remove File Extension
strTargetFile = Left(strTargetFile, (Len(strTargetFile) - 4))

strTargetFile = strTargetFile & "_BAK" & ".mdb"

'GetBackEnd Path
For Each Tdf In CurrentDB.TableDefs

If Len(Tdf.Connect) Then

strBEFile = Tdf.Connect
'password in Connect string means there are 2 '=' so
'use Instr Reverse
strBEFile = Mid(strBEFile, (InStrRev(strBEFile, "=") + 1))

strBEPath = Left(strBEFile, ((InStrRev(strBEFile, "\") - 1)))
'One table is sufficient
Exit For

End If

Next

If Len(v_BackupPath) Then

strTargetFolderPath = v_BackupPath

Else

strTargetFolderPath = strBEPath

End If

strTargetFolderPath = strTargetFolderPath & "\Backup"

If Not (FSO.FolderExists(strTargetFolderPath)) Then

FSO.CreateFolder strTargetFolderPath

End If

strTargetFile = strTargetFolderPath & "\" & strTargetFile

FSO.CopyFile strBEFile, strTargetFile

'If you got here then it worked
MakeBackupCopy = True

If v_Context = "NoMessage" Then

'Do Nothing

Else

MsgBox "Backup Completed", vbInformation, "BACKUP COMPLETE"

End If

Exit_Error_MakeBackupCopy:
Set Tdf = Nothing
Set File = Nothing
Set FSO = Nothing
Exit Function

Error_MakeBackupCopy:
MakeBackupCopy = False
RespondToError "MakeBackupCopy", Err.Number, Err.Description, "Backup Failed"
Resume Exit_Error_MakeBackupCopy

End Function
[/tt]
 
Thanks for the reply Que.... what would have to be altered to allow this code to work with a unified database?

Thanks again

Charles
 
Just substitute

strBEFile = currentproject.path & "\" & currentproject.name

for this

'GetBackEnd Path
For Each Tdf In CurrentDB.TableDefs

If Len(Tdf.Connect) Then

strBEFile = Tdf.Connect
'password in Connect string means there are 2 '=' so
'use Instr Reverse
strBEFile = Mid(strBEFile, (InStrRev(strBEFile, "=") + 1))

strBEPath = Left(strBEFile, ((InStrRev(strBEFile, "\") - 1)))
'One table is sufficient
Exit For

End If

Next

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top