Create Databse

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello.
I have a access 2003 database and i need to export a table to another db.
This target Db doesn't exist, so i need to prompt the user to select the
target directory for this db.
How can i programatically create a new database ?


Thanks.

Luis
 
This example shows how to programmatically create a new database, and set
the properties to stop it corrupting:

Sub CreateDatabaseDAO()
Dim dbNew As DAO.Database
Dim prp As DAO.Property
Dim strFile As String

'Create the new database.
strFile = "C:\SampleDAO.mdb"
Set dbNew = DBEngine(0).CreateDatabase(strFile, dbLangGeneral)

'Create example properties in new database.
With dbNew
Set prp = .CreateProperty("Perform Name AutoCorrect", dbLong, 0)
.Properties.Append prp
Set prp = .CreateProperty("Track Name AutoCorrect Info", _
dbLong, 0)
.Properties.Append prp
End With

'Clean up.
dbNew.Close
Set prp = Nothing
Set dbNew = Nothing
Debug.Print "Created " & strFile
End Sub

You can then copy the table to the target database with:
strSql = "SELECT * INTO Table1 IN ""C:\SampleDAO.mdb"" FROM Table1;"
dbLocal.Execute strSql, dbFailOnError

For the code to pop up the Windows Browse button for the user to select a
location, see:
http://www.mvps.org/access/api/api0002.htm
or if you want them to supply the file name as well:
http://www.mvps.org/access/api/api0001.htm
 
Back
Top