The following code was written by Helen Feddema and posted on her website to be freely downloaded. It's purpose is to backup the current database; however, I've split my DB and would like to back up the backend at the same time as the frontend. You'll see my additions anywhere "BackendDB" is mentioned. However, I get an "Error 52: Bad File Name" when it gets to backing up the backend (the frontend piece still works just fine). Any suggestions on what I'm missing? Thanks in advance.
Code:
Private Sub cmdBackup_Click()
On Error GoTo ErrorHandler
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strCurrentDB As String
Dim strBackendDB As String
Dim strCurrentDBNoExt As String
Dim strBackendDBNoExt As String
Dim fso As Scripting.FileSystemObject
Dim strTitle As String
Dim strPrompt As String
Dim strPrompt2 As String
Dim intReturn As Integer
Dim strDayPrefix As String
Dim strSaveName As String
Dim strSaveBEName As String
Dim strBackupPath As String
Set fso = CreateObject("Scripting.FileSystemObject")
strCurrentDB = Application.CurrentProject.Name
'Trim off extension
strCurrentDBNoExt = Mid(strCurrentDB, 1, Len(strCurrentDB) - 4)
strBackendDB = Application.CurrentProject.Name & "_be.mdb"
strBackendDBNoExt = Mid(strBackendDB, 1, Len(strBackendDB) - 4)
Debug.Print "Current db: " & strCurrentDB
strBackupPath = Application.CurrentProject.Path & "\Backups\"
strCurrentDB = Application.CurrentProject.Path & "\" & strCurrentDB
strBackendDB = Application.CurrentProject.Path & "\" & strBackendDB
Debug.Print "Current db with path: " & strCurrentDB
strDayPrefix = Format(Date, "mm-dd-yyyy")
strSaveName = strCurrentDBNoExt & " " & SaveNo & ", " & strDayPrefix & ".mdb"
strSaveName = strBackupPath & strSaveName
strSaveBEName = strBackendDBNoExt & " " & SaveNo & ", " & strDayPrefix & ".mdb"
strSaveBEName = strBackupPath & strSaveBEName
Debug.Print "Backup save name: " & strSaveName
strTitle = "Database backup"
strPrompt = "Save database to " & strSaveName & "?"
strPrompt2 = "Save backend to " & strSaveBEName & "?"
intReturn = MsgBox(strPrompt, vbYesNo, strTitle)
If intReturn = vbYes Then
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tblBackupInfo")
With rst
.AddNew
![SaveDate] = Format(Date, "mm-dd-yyyy")
![SaveNumber] = SaveNo
.Update
.Close
End With
fso.CopyFile strCurrentDB, strSaveName
fso.CopyFile strBackendDB, strSaveBEName
Me.Refresh
End If
ErrorHandlerExit:
Exit Sub
ErrorHandler:
MsgBox "Error No: " & Err.Number & "; Description: " & _
Err.Description
Resume ErrorHandlerExit
End Sub