Results 1 to 4 of 4
  1. #1
    WithoutPause is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    62

    Automatic backup.

    https://www.youtube.com/watch?v=Tkh8JOZ3Ah8



    I used that as the source. Here's the issues.

    1. If possible, I would like the backup to happen when a user exits the application.
    2. I would like the backup to be overwritten if done in the same day.
    3. Unlike in the video, I get a number of Microsoft Access Security Notices when running the code.

    Current code.
    Code:
    Sub BackUp()
         
        Dim sFile As String, oDB As DAO.Database
         
        sFile = CurrentProject.Path & "\" & Format(Date, "m-d-yy") & ".accdb"
        If Dir(sFile) <> "" Then Kill sFile
         
        Set oDB = DBEngine.Workspaces(0).CreateDatabase(sFile, dbLangGeneral)
        oDB.Close
         
        Dim oTD As TableDef
         
        For Each oTD In CurrentDb.TableDefs
            If Left(oTD.Name, 4) <> "MSys" Then
                DoCmd.CopyObject sFile, , acTable, oTD.Name
            End If
        Next oTD
    
    
        ' No current queries
        ' Dim oQD As QueryDefs
        'For Each oQD In CurrentDb.QueryDefs
        '    If Left(oDQ.Name, 1) <> "~" Then
        '        DoCmd.CopyObject sFile, , acQuery, oQD.Name
        '    End If
        'Next oQD
        
        Dim oForm As Object
        For Each oForm In CurrentProject.AllForms
            DoCmd.CopyObject sFile, , acForm, oForm.Name
        Next oForm
        
        Dim oReport As Object
        For Each oReport In CurrentProject.AllReports
            DoCmd.CopyObject sFile, , acReport, oReport.Name
        Next oReport
        
        Dim oMod As Object
        For Each oMod In CurrentProject.AllReports
            DoCmd.CopyObject sFile, , acModule, oMod.Name
        Next oMod
        
        Dim oMac As Object
        For Each oMac In CurrentProject.AllMacros
            DoCmd.CopyObject sFile, , acReport, oMac.Name
        Next oMac
         
    End Sub
    
    
    Function AutoRun()
        Dim sFile As String
        sFile = "C:\Users\(username)\ACEDAO.dll"
        On Error Resume Next
        Application.VBE.ActiveVBProject.References.AddFromFile sFile
        BackUp
    End Function

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Why not create a copy of the entire file? It seems you are importing all objects anyway.

  3. #3
    WithoutPause is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    62
    If there is an easier way, then I'm interested. I Googled the solution and most solutions were simply Save & Publish. I'm trying to make the backing up as dummy proof as possible.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Here is some code that will copy and paste a test file from your C drive. This is a re-factored version of the OP's version. It may still benefit from some additional massaging but it gets the job done.

    Code:
    Dim sourceFile As String, destinationFile As String
    Dim aFSO As Variant
    'Dim path As String, name As String
    sourceFile = "C:\Test\CopyMe.txt"
    'path = CurrentProject.path
    'name = CurrentProject.name
    destinationFile = "C:\Test\Result\CopyMe_Copy.txt"
    'this detects if the file name already exists
    If Dir(destinationFile) <> "" Then
    MsgBox "This file name already exists! Choose another destinationFile or delete the existing destinationFile first."
    End If
    'this creates a backup into destination path
    If Dir(destinationFile) = "" Then
    Set aFSO = CreateObject("Scripting.FileSystemObject")
    aFSO.CopyFile sourceFile, destinationFile 'You can choose to overwrite existing file by including...   , True
    MsgBox "A copy of your test file has been stored under " & destinationFile
    End If

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Backup
    By sergran in forum Programming
    Replies: 19
    Last Post: 07-17-2013, 12:27 AM
  2. Automatic backup
    By timpepu in forum Access
    Replies: 4
    Last Post: 08-14-2012, 01:38 PM
  3. backup from my data
    By smahdih in forum Access
    Replies: 3
    Last Post: 11-06-2011, 12:03 AM
  4. Can't backup Db
    By wislndixie in forum Access
    Replies: 1
    Last Post: 08-19-2011, 01:36 PM
  5. Ezy BackUp
    By FogLine in forum Programming
    Replies: 0
    Last Post: 07-04-2010, 06:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums