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
367 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
  • 2
  • 2
4 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

758 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now