Results 1 to 8 of 8
  1. #1
    Harley Guy is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2010
    Posts
    57

    Create a Macro to run backup of database

    Hello all. I do a manual back-up of my databases each week by going into "File" then "Save & Publish" and click on "Back-up Database" and it will place the back-up in a location of my choosing. I would love to create a macro that I could place on the switchbaord so I could do this with one click.

    I am unfamiliar with creating macros...can someone give me an idea on how to go about this?

    Thanks!

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I use task scheduler to launch a VB script file.

    Here is the code for the VBS


    Code:
    Dim sourceFile
    Dim destinationFile
    Dim strDesFilName
    Dim strNow
    Dim aFSO
    strNow = Year(Date) & "_" & Month(Date) & "_" & Day(Date) & "_" & Hour(Now) & Minute(Now) & "_" & Second(Now)
    strDesFilName = "Inv_Copy_" & strNow & ".accdb"
    destinationFile = "C:\Inventory_Backup\" & strDesFilName
    sourceFile = "\\ServerName\Inventory\Inventory.accdb"
    Set aFSO = CreateObject("Scripting.FileSystemObject")
    aFSO.CopyFile sourceFile, destinationFile

  3. #3
    Harley Guy is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2010
    Posts
    57
    So this is a code that would schedule back-ups and I wouldn't need to do it manually? It's a little out of my league but I like the idea if that's the case.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    The code would not schedule the back up. The code will create a backup and use the current system time as part of the file name. In order to schedule the backup you would have to use Task Scheduler in Windows. The hardest part is probably getting all of the settings in Task Scheduler correct.

    You can start with the code here and test it with a dummy file in a couple of temp folders.

    Identify the text in my code for the file paths and adjust that part of the code to match your new temp folders/file names. Be sure to include file extensions in the names of your files.

    For instance, the following line of code would need to be edited so it will copy the file you want to back up. Right now, it is looking for a server named "ServerName" and a folder named "Inventory" where there is an accdb file named "Inventory"
    sourceFile = \\ServerName\Inventory\Inventory.accdb

  5. #5
    Harley Guy is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2010
    Posts
    57
    Ah well...it was a shot in the dark. Since it is only once per week, I will continue to do it manually. This would be a little bit out of my league. Thanks anyway!

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    It aint that bad. Navigate to your DB file using windows explorer and set you cursor in the Address field at the top of the window. You will see some text highlighted. This will be your path. Maybe something like

    C:\Test

    This is using the drive letter for a local drive on the machine. The other example I provided is a path on a network.

  7. #7
    killdozer is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jan 2014
    Location
    New Brunswick
    Posts
    9
    If I want to tell the user that the database was succeffully backed up, how would I do that?

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,926
    Use a MsgBox call in the script.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. How to backup my database to my website
    By instanceoftime in forum Access
    Replies: 1
    Last Post: 12-06-2013, 10:48 PM
  2. Making daily backup of database
    By JeroenMioch in forum Access
    Replies: 5
    Last Post: 10-30-2013, 04:50 PM
  3. Save database as backup
    By MadeCurler in forum Access
    Replies: 3
    Last Post: 11-08-2012, 06:59 AM
  4. access database backup...
    By alex_raju in forum Access
    Replies: 5
    Last Post: 07-17-2011, 09:00 AM
  5. Database backup automation
    By aat in forum Access
    Replies: 2
    Last Post: 09-17-2010, 07:24 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