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
382 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Lync meeting or Lync conferencing is what many organizations would like to deploy to allow them save money. But companies are now giving up for various reasons, one of which is that they cannot join external meetings (non-federated company meetings)…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

828 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