Backup issue (Export only few tables to a new file)

awa786

Registered User.
Local time
Today, 19:45
Joined
Jul 7, 2015
Messages
23
Hi,
I am going to make a backup function to export some tables from my access database to another ms access file, i have searched google before and found this code to export all the table except systems tables containing "Msys"
code is:
Code:
Public Function fExportAllDBObjects()
On Error Resume Next
Const conPATH_TO_BKUPS As String = "C:\DB Backups\"
Dim strAbsoluteBkUpPath As String
Dim aob As AccessObject
Dim strDBName As String
Dim wrkSpace As Workspace
Dim dbBackup As Database
 
DoCmd.Hourglass True
 
'Retrive the Current Database Name only, strip out .mdb
strDBName = Replace(Mid$(CurrentDb.Name, InStrRev(CurrentDb.Name, "\") + 1), ".mdb", "")
 
'Make the Backup DB Name unique for each Date
strDBName = strDBName & "_" & Format$(Date, "mmddyyyy") & ".mdb"
 
strAbsoluteBkUpPath = conPATH_TO_BKUPS & strDBName
 
'If a Bacup already exists for this Date, then DELETTE it
If Dir$(strAbsoluteBkUpPath) <> "" Then
  Kill strAbsoluteBkUpPath
End If
 
'Get Default Workspace.
Set wrkSpace = DBEngine.Workspaces(0)
 
'Create the Database
Set dbBackup = wrkSpace.CreateDatabase(strAbsoluteBkUpPath, dbLangGeneral)
 
'Export all Tables
For Each aob In CurrentData.AllTables
[COLOR="Red"]  If Mid$(aob.Name, 2, 3) <> "Sys" Then     'Don't Export System Tables
    DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, _
                           acTable, aob.Name, aob.Name[/COLOR]
  End If
Next
 

 
DoCmd.Hourglass False
End Function


But in that code all the tables are exported to a new file like the, users, flags,and all the tables the others table that i don't want to export.


for example: tb1,tb2,tb3,tb4,tb5,tb6,tb7,tb8,tb9,tb10
these are the tables in my database and i want to only export only three (tb3,tb7,tb9) tables to a single ms access file .

Please help me.
Thanks and Regards.
 
You could drop the loop and hardcode the tables names, or put the tables names in a table and use a recordset and a loop.

Code:
[COLOR=Red]DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, [/COLOR][COLOR=Red][COLOR=Red]acTable, "Tb3", [/COLOR][/COLOR][COLOR=Red][COLOR=Red][COLOR=Red][COLOR=Red]"Tb3"[/COLOR][/COLOR][/COLOR] 
[/COLOR][COLOR=Red][COLOR=Red]DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, [/COLOR][COLOR=Red][COLOR=Red]acTable, "Tb7", [/COLOR][/COLOR][COLOR=Red][COLOR=Red][COLOR=Red][COLOR=Red]"Tb7"[/COLOR][/COLOR][/COLOR] 
[/COLOR][/COLOR][COLOR=Red][COLOR=Red][COLOR=Red]DoCmd.TransferDatabase acExport, "Microsoft Access", strAbsoluteBkUpPath, [/COLOR][COLOR=Red][COLOR=Red]acTable, "Tb9", [/COLOR][/COLOR][COLOR=Red][COLOR=Red][COLOR=Red][COLOR=Red]"Tb9"[/COLOR][/COLOR][/COLOR] [/COLOR][/COLOR] [/COLOR]
 
WORKS

Thanks.
 
You're welcome, good luck.
 

Users who are viewing this thread

Back
Top Bottom