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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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 …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

911 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

20 Experts available now in Live!

Get 1:1 Help Now