Results 1 to 2 of 2
  1. #1
    Neil Bingham is offline Novice
    Windows XP Access 2000
    Join Date
    Feb 2009
    Location
    Cumbria UK
    Posts
    14

    Automating db backup to another location on close

    I work on several databases on my laptop. I would like to have macro/code so that when I close a db it is automatically copied to another location (ie my networked desktop pc or an external hard drive) I do this manually now - any code has to answer yes in the pop up box which says "file already exists - do you wish to overwrite" Can anyone help please?

  2. #2
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,928
    your would need code in a form close event - and that form would need to be one that a) is open b) closes last and c) does not close at any other time.

    there is no event that I am aware of which runs when the access application closes - only as above when the application closes forms - and there are ways which this might be circumnavigated (e.g. windows is closed)

    That said, in your form close event you would have something like

    Code:
    Dim fso As Object
    
    Set fso = VBA.CreateObject("Scripting.FileSystemObject")
    If MsgBox("Do you want to backup this file?", vbYesNo) = vbYes Then
        On Error Resume Next
        fso.copyfile CurrentDb.Name, "C:" & Mid(CurrentDb.Name, InStrRev(CurrentDb.Name, "\")), False
        If Err.Number = 58 Then 'file already exists
            If MsgBox("File already exists - do you want to overwrite?", vbYesNo) = vbYes Then
                fso.copyfile CurrentDb.Name, "C:" & Mid(CurrentDb.Name, InStrRev(CurrentDb.Name, "\")), True
            End If
        End If
    End If
    change C: to the directory you want to use

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

Similar Threads

  1. Replies: 1
    Last Post: 03-21-2015, 11:55 AM
  2. Replies: 8
    Last Post: 05-11-2014, 08:52 AM
  3. Replies: 4
    Last Post: 01-31-2014, 11:47 AM
  4. Automating compact/Repair and backup of BE
    By togo in forum Programming
    Replies: 1
    Last Post: 12-27-2012, 03:29 PM
  5. Replies: 2
    Last Post: 06-20-2011, 03:10 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