Results 1 to 9 of 9
  1. #1
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98

    Auto backup on entire database close, forms included

    I have a database with multiple forms and I would like to on close I would assume of the form, save a backup to a specific folder. This will all change once I move the database to the server but for now want a backup on my machine.

    Here is my code:

    Code:
    Private Sub Form_Close()
    Call db_backup
    End Sub
    Below is in a module


    Code:
    Option Compare Database
    Option Explicit
    Public Function db_backup()
    Dim sourceFile As String, destinationFile As String
    Dim aFSO As Variant
    Dim path As String, name As String
    sourceFile = CurrentProject.QualityTest
    path = CurrentProject.path
    name = CurrentProject.name
    destinationFile = path & "c:\users\AD36742\documents\db backups - please do not remove\" & Left(name, Len(name) - 6) & "_backup" & "_" & _
    Year(Now) & "_" & Month(Now) & "_" & Day(Now) & ".accdb"
    'this removes a file created on the same day
    If Dir(destinationFile) <> "" Then
    Kill destinationFile
    End If
    'this creates a backup into destination path
    If Dir(destinationFile) = "" Then
    Set aFSO = CreateObject("Scripting.FileSystemObject")
    aFSO.CopyFile sourceFile, destinationFile, True
    MsgBox "A database backup has been stored under " & destinationFile
    End If
    End Function
    The problem is when I run this the program will give me an error saying: runtime error 438 object does not support this property or method

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    It looks to me like this:
    Code:
    path = CurrentProject.path
    name = CurrentProject.name
    destinationFile = path & "c:\users\AD36742\documents\db backups - please do not remove\"...
    ...should *not* begin with path!
    FYI: PATH is a reserved word as well.

  3. #3
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98
    Thanks. It does not have path! It runs but it does nothing. My Access db is named Qualitytest so I am confused why this is not working.

  4. #4
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98
    Maybe I don't need to call the function and it just does it. Nope, that did not work. It let me close the DB and nothing was saved anywhere

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The code you posted indicated it did. What do you think this line will do? sourceFile = CurrentProject.QualityTest

  6. #6
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98
    Isn't it supposed to look at qualitytest as my source file and then back that up?

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Why not look at sourceFile and see what you have?

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Do you know how to do that? A MsgBox sourceFile will do it.

  9. #9
    cuddles is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    98
    got it. perfect thnx

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

Similar Threads

  1. Auto Backup Backend When Opening Frontend
    By Elfear in forum Programming
    Replies: 3
    Last Post: 04-25-2019, 10:58 AM
  2. Replies: 6
    Last Post: 05-10-2014, 05:11 PM
  3. auto backup of database with every open
    By joshynaresh in forum Database Design
    Replies: 14
    Last Post: 10-01-2013, 10:10 AM
  4. Backup of forms
    By torunsu in forum Access
    Replies: 1
    Last Post: 08-08-2011, 08:38 AM
  5. Auto Backup
    By jo15765 in forum Access
    Replies: 17
    Last Post: 11-23-2010, 11:57 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