Results 1 to 6 of 6

Thread: [resolved]Backing-up a Ms Access database

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    England
    Posts
    29

    [resolved]Backing-up a Ms Access database

    Hi everyone,

    I want to somehow make a back-up copy of a database from visual basic, maybe by making an exact copy of the database or somehow. please someone, if you got any suggestions please post them...any codes would be great. thanks
    Last edited by Adrian_struggel; Apr 11th, 2004 at 06:39 PM.

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    MS Access type database is a single file DB and therefore backup is very simple - just copy original file to a backup folder:
    VB Code:
    1. FileCopy App.Path & "\Data\MyDB.mdb", App.Path & "\Archive\" & Format(Now, "mm_dd_yyyy") & ".mdb"

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    England
    Posts
    29

    hey thanks RhinoBull,

    thanks, 1 question,
    how would i go on about doing it...i want it to be called from a button, say the buttons name is cmdBackUp
    please...help me..thanx again

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Compile the following code and create a Scheduled Task so this program will run once a day (better during OFF hours):
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     'check for archive folder and create one if it doesn't exist
    5.     If Dir(App.Path & "\Archive", vbDirectory) = "" Then
    6.         MkDir App.Path & "\Archive"
    7.     End If
    8.     'check for error folder and create one if it doesn't exist
    9.     If Dir(App.Path & "\Error", vbDirectory) = "" Then
    10.         MkDir App.Path & "\Error"
    11.     End If
    12. End Sub
    13.  
    14. Private Sub Command1_Click()
    15.     ArchiveDB App.Path & "\Data\MyDB.mdb", _
    16.               App.Path & "\Archive\" & Format(Now, "mm_dd_yyyy") & ".mdb"
    17. End Sub
    18.  
    19. Public Function ArchiveDB(sSource As String, sDestination As String) As Boolean
    20. '===============================================================================
    21. On Error GoTo ErrHandler
    22.    
    23.     FileCopy sSource, sDestination
    24.     Exit Function
    25.  
    26. ErrHandler:
    27. '------------
    28.     Open App.Path & "\Error\erros.txt" For Append As #1
    29.         Print #1, Now() & vbTab & Err.Number & ": " & Err.Description
    30.     Close #1
    31.     Exit Function
    32.  
    33. End Function

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Location
    England
    Posts
    29

    hey RhinoBull, your the MAN

    thanks a lot....did you just type that whole code now...well anyway ...thanks a lot...you'r the man..
    thanks a lot
    bye

  6. #6
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132
    Yes, it's a brand new quick and dirty sample code for you Adrian. Despite it is a working sample - it needs some work to be done to tune it up.

    Cheers.

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