backup tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coachafrane
    New Member
    • Mar 2014
    • 7

    backup tables

    I have this code that backs up all my tables in the same folder.

    I want to however back up only specified table with names; “operation al areas”, “Communiti es”, “Zones” and “Projects” .

    Can I please get help on how to integrate that into my existing code or any other way to achieve that


    Code:
    Sub backup()
       Dim dTime As Date
        On Error Resume Next
        dTime = InputBox("Create a backup at", , Time + TimeValue("00:00:05"))
        If Err.Number <> 0 Then Exit Sub
        Do Until Time = dTime
            DoEvents
        Loop
        Dim sfile As String, oDB As DAO.Database
        'IF DAO.dll does not load, then find
        'ACEDAO.dll in Program Files (64-bit machine) or MS Office AC DB Engine Object
        sfile = CurrentProject.Path & "\" & "Staff Data" & ".accdb"
        If Dir(sfile) <> "" Then Kill sfile
        Set oDB = DBEngine.Workspaces(0).CreateDatabase(sfile, dbLangGeneral)
        oDB.Close
        DoCmd.Hourglass True
        
        Dim oTD As TableDef
        For Each oTD In CurrentDb.TableDefs
            If Left(oTD.NAME, 4) <> "MSys" Then
                DoCmd.CopyObject sfile, , acTable, oTD.NAME
                'OR: DoCmd.TransferDatabase acExport,"Microsoft Access", sFile, acTable,oTD
            End If
        Next oTD
        
        DoCmd.Hourglass False
        MsgBox "Backup is stored in the same folder"
    End Sub
    Last edited by Rabbit; Apr 6 '14, 06:37 PM. Reason: Please use code tags when posting code or formatted data.
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1288

    #2
    coachafrane,
    Here's one way. Put this code in place of your "if left" block of code.

    Code:
    Select Case oTD.NAME
    case “operational areas”
         DoCmd.CopyObject sfile, , acTable, oTD.NAME
    case “Projects”.
         DoCmd.CopyObject sfile, , acTable, oTD.NAME
    case “Communities”
         DoCmd.CopyObject sfile, , acTable, oTD.NAME
    case “Zones”
         DoCmd.CopyObject sfile, , acTable, oTD.NAME
        
    End Select
    And please remember to use Code tags around any program code you post. It's simple, just click the [CODE/] button and type your code between the tags that appear.

    Jim

    Comment

    Working...