Backup .accdb (1 Viewer)

pekajo

Registered User.
Local time
Today, 22:33
Joined
Jul 25, 2011
Messages
132
Hi,
Is there a way to backup the entire database using vb.
The backups I have found only appear to backup data not the changed code in the current session.
Thanks for any help
Peter
 

Gasman

Enthusiastic Amateur
Local time
Today, 11:33
Joined
Sep 21, 2011
Messages
14,038
Yes, you just backup the other file?

Here is what I have used in the past.

Code:
Sub CreateBackup(Optional strDBType As String)
    Dim strDBpath As String, ext As String, tmp As String
    Dim strPath As String, strBackupPath As String, strDB As String
    
    
    'tmp = CurrentDb.Name    'or maybe this should be the name of your BE
    'strDBType = "FE"
    strDBpath = GetAccessBE_PathFilename("tblUser")
    'strPath = Left(strDBpath, InStrRev(strDBpath, "\"))
    strPath = Left(strDBpath, Len(strDBpath) - InStrRev(strDBpath, "\") + 1)
    strBackupPath = strPath & "Backup\"
    
    'Will nor backup front and back end database
    If strDBType = "FE" Then
        strDBpath = CurrentDb.Name
    End If
    strDB = Right(strDBpath, Len(strDBpath) - InStrRev(strDBpath, "\"))
    
    With CreateObject("Scripting.FileSystemObject")
        'ext = "." & .GetExtensionName(tmp)
        tmp = strBackupPath & Format(Now(), "yyyymmdd_hhnnss") & "_" & strDB
        .CopyFile strDBpath, tmp
    End With
    MsgBox strDBType & " Database saved as " & tmp
    
    
End Sub

Then it is called with CreateBackup("FE") or ("BE")

Here is the code for the function used in the code above
Code:
Function GetAccessBE_PathFilename(pTableName As String) As String
'strive4peace

   ' RETURN
   '  the file path and file name of the BE database
   '  "" if the table is not linked
   
   On Error GoTo Proc_Err
   
   Dim db As DAO.Database _
      , tdf As DAO.TableDef
   
   GetAccessBE_PathFilename = ""
   
   Set db = CurrentDb
   Set tdf = db.TableDefs(pTableName)
   
   If Len(tdf.Connect) = 0 Then
      GoTo Proc_Exit
   End If
   
   ' look at Connect string - Database Type is the first thing specified
   ' if the BE is Access
   If InStr(tdf.Connect, ";DATABASE=") <> 1 Then
      GoTo Proc_Exit
   End If
   
   GetAccessBE_PathFilename = Mid(tdf.Connect, 11)
    
Proc_Exit:
   On Error Resume Next
   Set tdf = Nothing
   Set db = Nothing
   Exit Function
  
Proc_Err:
   MsgBox Err.Description, , _
        "ERROR " & Err.Number _
        & "   GetAccessBE_PathFilename"

   Resume Proc_Exit
   Resume
             
End Function

HTH
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 07:33
Joined
Feb 19, 2002
Messages
42,970
Here is a sample I created. It utalizes a hidden form to back up the database whenever it determines that you have changed an object. In order to not annoy your users, you should always modify the code in the backup form to look for specific userIDs so that only you get prompted since the users don't actually change the FE.
 

Attachments

  • AutoCreateBackupFormAndObjects.accdb
    884 KB · Views: 67

theDBguy

I’m here to help
Staff member
Local time
Today, 04:33
Joined
Oct 29, 2018
Messages
21,357
Hi,
Is there a way to backup the entire database using vb.
The backups I have found only appear to backup data not the changed code in the current session.
Thanks for any help
Peter
Hi Peter. Just curious, who is changing the code in the current session? You or your users?
 

mjdemaris

Working on it...
Local time
Today, 04:33
Joined
Jul 9, 2015
Messages
424
I usually have several copies of the front end and back end. For production, the front and back ends are stored on the server, and I use a batch file to backup those files to another location. This way I can use the task scheduler to call the batch file.

The development front end is usually a close copy of the production front end, so if something goes wrong, or a quick change is needed, I can push that out rather quickly.

Then I have the major changes in a separate front end file - since I am still learning and tinkering with ideas, I don't want to push major changes without testing them adequately.
 

Users who are viewing this thread

Top Bottom