Results 1 to 15 of 15

Thread: Backup Access database automatically

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Posts
    149

    Question Backup Access database automatically

    Hi,

    I need to backup my Access database on every Friday night. Does anyone has any idea how to go about doing it? Do we actually need to keep our application active all the time inorder to achieve this requirement ? Thanks !

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    What do you want to back it up to?

    A network drive?
    A diskette?
    A CD?
    Tape?

    VBs FileCopy would work, but only if the database is closed.

    On the other hand, the CopyFile method of the FileSystemObject will copy a file, even if it is open.

  3. #3
    Lively Member
    Join Date
    Sep 2002
    Posts
    103
    We discovered our automatic backup wasn't backing up databases in use, (and most were in use at the backup time). We now use a housekeeping program to make a copy of the database, so that this, which is not in use, gets backed up. The mirror copy also provides a convenient short term backup.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Did you develop the "housekeeping program" that you mentioned aidan?

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Posts
    149
    I will backup the database in the network drive.

    Hack, do you have a simple example on how to use the CopyFile method? So if some users are updating data at the same time when you backup the database, will there be any problem ? How do you deal with such situation ?

    aidan, how do you create a housekeeping program and how you detect whether the database is in used ?

    Actually, my main concern is that, I can I do it automatically?

    thank in advance.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    VB Code:
    1. 'Set a reference to the FileSystemObject (Microsoft Scripting Runtime)
    2. Option Explicit
    3.  
    4. Private BkUpDb As New FileSystemObject
    5.  
    6. Private Sub Form_Load()
    7. BkUpDb.CopyFile "c:\program files\qcap\qcap.Mdb", "W:\systems\hack\qcap.Mdb", True
    8. End Sub

  7. #7
    Lively Member
    Join Date
    Sep 2002
    Posts
    103
    What hack has written is pretty much what I use. It checks to see if a folder exists with today's date on it, if it doesn't then it makes it and copies the files. It doesn' t matter if they are in use, although obviously any changes which haven't been updated yet won't be saved.

    The function can be triggered manually or with a timer

    Here is the code
    PHP Code:
    Public Function MDbackupdatabases() As Long
        Dim DBname
    $(5)
        
    Dim oldfolder$
        
    Dim newfolder$
        
    Dim t&
        
    Dim fso As Object 'As New scripting.FileSystemObject
        Set fso = CreateObject("Scripting.FileSystemObject")
        oldfolder = "T:\"
        newfolder = "T:\DBbackups " & format(Date, "ddMMyy")
        retval = MDcreateFolder(newfolder)
        If retval Then '
    folder did not previously exist
            DBname
    (0) = "Contacts2000.mdb"
            
    DBname(1) = "Project2000.mdb"
            
    DBname(2) = "newindexes2000.mdb"
            
    For 0 To 2 'cycle through all files
                fso.copyfile oldfolder & DBname(t), newfolder & DBname(t), False  '
    false means will not overwrite
            Next t 
    'cycle through all files
            MDbackupdatabases = 1
        End If '
    folder did not previously exist 

  8. #8
    Lively Member
    Join Date
    Sep 2002
    Posts
    103
    Oops - I formatted to PHP not VB code

    I am planning to improve it by making it carry out a test access of the database to check that it hasn't been corrupted before the file is copied, but I haven't got round to doing this yet.

  9. #9
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397
    I'm not sure if this is exactly what you are looking for, but I use it to make copy and compact the DB at the same time.

    http://support.microsoft.com/default...;en-us;Q209979

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Sep 2001
    Posts
    149
    Thanks texas, but I am using Access 97 and Visual Basic 6. The article you provided is for Access 2000.

  11. #11
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Even though the article if for Access 2000, I wouldn't be surprized to discover you could use the fundamentals of it for Access 97.

    Give it shot and see what happens.

  12. #12
    Hyperactive Member
    Join Date
    Aug 2001
    Location
    Austin
    Posts
    397
    I took out the timer event code and set the DB to autoexec the code when the DB opened. i.e. OnOpen event of the form. That way VB can call it or in my case I used the Scheduled Tasks wizard to run it.

  13. #13
    New Member
    Join Date
    Oct 2012
    Posts
    1

    Re: Backup Access database automatically

    Quote Originally Posted by aidan View Post
    What hack has written is pretty much what I use. It checks to see if a folder exists with today's date on it, if it doesn't then it makes it and copies the files. It doesn' t matter if they are in use, although obviously any changes which haven't been updated yet won't be saved.

    The function can be triggered manually or with a timer

    Here is the code
    PHP Code:
    Public Function MDbackupdatabases() As Long
        Dim DBname
    $(5)
        
    Dim oldfolder$
        
    Dim newfolder$
        
    Dim t&
        
    Dim fso As Object 'As New scripting.FileSystemObject
        Set fso = CreateObject("Scripting.FileSystemObject")
        oldfolder = "T:\"
        newfolder = "T:\DBbackups " & format(Date, "ddMMyy")
        retval = MDcreateFolder(newfolder)
        If retval Then '
    folder did not previously exist
            DBname
    (0) = "Contacts2000.mdb"
            
    DBname(1) = "Project2000.mdb"
            
    DBname(2) = "newindexes2000.mdb"
            
    For 0 To 2 'cycle through all files
                fso.copyfile oldfolder & DBname(t), newfolder & DBname(t), False  '
    false means will not overwrite
            Next t 
    'cycle through all files
            MDbackupdatabases = 1
        End If '
    folder did not previously exist 
    Hi, above Aiden has added a script that backups even when the database is in use. I am looking for this exact thing for accesss. As Aiden has written this in PHP, does anyone ahve something similar for access please?

    Thanks,
    Ian.

  14. #14
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Backup Access database automatically

    That's not PHP... it's VB... he jsut used the PHP syntax highlighter by mistake... but it's VB code all the way through.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  15. #15
    Junior Member
    Join Date
    Apr 2015
    Posts
    23

    Re: Backup Access database automatically

    Hello guys
    Code:
    Public Function MDbackupdatabases() As Long 
        Dim DBname$(5) 
        Dim oldfolder$ 
        Dim newfolder$ 
        Dim t& 
        Dim fso As Object 'As New scripting.FileSystemObject 
        Set fso = CreateObject("Scripting.FileSystemObject") 
        oldfolder = "T:\" 
        newfolder = "T:\DBbackups " & format(Date, "ddMMyy") 
        retval = MDcreateFolder(newfolder) 
        If retval Then 'folder did not previously exist 
            DBname(0) = "Contacts2000.mdb" 
            DBname(1) = "Project2000.mdb" 
            DBname(2) = "newindexes2000.mdb" 
            For t = 0 To 2 'cycle through all files 
                fso.copyfile oldfolder & DBname(t), newfolder & DBname(t), False  'false means will not overwrite
            Next t 'cycle through all files 
            MDbackupdatabases = 1 
        End If 'folder did not previously exist
    I'm getting an error in this lines of codes
    Code:
    newfolder = "T:\DBbackups " & format(Date, "ddMMyy")
    error is Type expected

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width