Results 1 to 4 of 4
  1. #1
    mdnikki is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2012
    Posts
    63

    Can I create an autoexec macro to backup a database


    I have created a database that a few people will be working in at different times. I would like a back up of the database created each time it is opened. Is it possible to create an autoexec macro to run that creates this. Or is there another way to have this db backed up each time.

    Thanks
    Nicol

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    In the autoexec ,RUNCODE myBackup()

    put this function in a module...

    Code:
    function myBackup()
    VDate= format(date,"yyyymmdd-hhnn")
    vSrc="c:\folder\myDb.accdb"
    vTarg="c:\folder\ backup\myDb-" & vDate & ".accdb"
    filecopy vSrc,vTarg
    end function
    Last edited by ranman256; 12-05-2016 at 10:45 AM.

  3. #3
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    If you have multiple users, and are worried about corruption, the very first thing you should do (if you have not done it already) is to split database.
    See: https://support.office.com/en-us/art...3-51b1d73498cc

    If your concern is more about the data getting changed and you want the original data, I would go about what you want to do a little differently.
    Create a batch file or VBS Script and give to the users to "run the program", and simply have the batch file/script do the following:
    - Create a copy of the back-end
    - Open the front-end

    Note that depending on how big your database is and how often people are going into it, this could suck up a lot of memory, unless you periodically purge old backups.

  4. #4
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,938
    not sure if filecopy will work if you are trying to copy a file that is open (i.e. the currentdb or the backend). If it doesn't, try something like (using variables from Ranmans code)

    Shell "cmd /c copy """ & vsrc & """ """ & vtarget & ""

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

Similar Threads

  1. Replies: 5
    Last Post: 06-21-2015, 02:51 PM
  2. AutoExec macro e-mail
    By robphillips79 in forum Macros
    Replies: 5
    Last Post: 02-09-2015, 03:04 PM
  3. Create a Macro to run backup of database
    By Harley Guy in forum Macros
    Replies: 7
    Last Post: 10-02-2014, 12:33 PM
  4. Autoexec Macro details?
    By cboshdave in forum Access
    Replies: 6
    Last Post: 11-20-2012, 01:46 PM
  5. Help Stopping AutoExec Macro
    By drewetzel in forum Access
    Replies: 2
    Last Post: 10-03-2011, 10:51 AM

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