Solved

How to create a vba procedure in Access 2010 to create a new database and export tables to the new Db

Posted on 2014-11-26
4
384 Views
Last Modified: 2014-12-08
Hi Experts

In Access 2010 I need a vba procedure to create a new database and export all the tables to this new database.
0
Comment
Question by:simsima_7876
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40466776
try this codes
Sub CreateNewDB()
Dim ws As Workspace
Dim db As Database
Dim strPathName As String

'Get default Workspace
Set ws = DBEngine.Workspaces(0)

'Path and file name for new db file
strPathName = CurrentProject.Path & "\NewDB.accdb"

'Make sure there isn't already a file with the name of the new database
If Dir(strPathName) <> "" Then Kill strPathName

'Create a new db file
Set db = ws.CreateDatabase(strPathName, dbLangGeneral)
db.Close
Set db = Nothing

End Sub
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40466814
here is the code to export the tables

Sub exportT()
Dim td As DAO.TableDef, db As DAO.Database, sql As String, strPathName As String
strPathName = CurrentProject.Path & "\NewDB.accdb"
Set db = CurrentDb
For Each td In db.TableDefs
    If Not td.Name Like "Msys*" Then
        sql = "SELECT [" & td.Name & "].* INTO [" & td.Name & "] IN '" & strPathName & "' FROM [" & td.Name & "]"
        db.Execute sql
    End If
Next
End Sub
0
 

Author Comment

by:simsima_7876
ID: 40486495
Thanks Ray.
That does it.
0
 

Author Closing Comment

by:simsima_7876
ID: 40486496
Thanks Ray
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question