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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to back up backend via code 1

Status
Not open for further replies.

itsuit

IS-IT--Management
Apr 23, 2002
53
US
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
 
The actual backend file name is "RAI Contact Management_be.mdb"; essentially it's the same file name as the frontend, but with the "_be" added.
 
Replace this:
strBackendDB = Application.CurrentProject.Name & "_be.mdb"
strBackendDBNoExt = Mid(strBackendDB, 1, Len(strBackendDB) - 4)
By this:
strBackendDB = strCurrentDBNoExt & "_be.mdb"
strBackendDBNoExt = strCurrentDBNoExt & "_be"


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV -

Perfect! Thanks so much for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top