Workspace.CreateDatabase method (DAO)
Applies to: Access 2013, Office 2013
Creates a new Database object, saves the database to disk, and returns an opened Database object (Microsoft Access workspaces only).
Syntax
expression .CreateDatabase(Name, Connect, Option)
expression A variable that represents a Workspace object.
Parameters
Name |
Required/optional |
Data type |
Description |
---|---|---|---|
Name |
Required |
String |
A String up to 255 characters long that is the name of the database file that you're creating. It can be the full path and file name. If your network supports it, you can also specify a network path, such as "\\server1\share1\dir1\db1". You can only create Microsoft Access database files with this method. |
Connect |
Required |
String |
|
Option |
Optional |
Variant |
A constant or combination of constants that indicates one or more options, as specified in Settings. You can combine options by summing the corresponding constants. |
Remarks
You can use one of the following constants for the locale argument to specify the CollatingOrder property of text for string comparisons.
Constant |
Collating order |
---|---|
dbLangGeneral |
English, German, French, Portuguese, Italian, and Modern Spanish |
dbLangArabic |
Arabic |
dbLangChineseSimplified |
Simplified Chinese |
dbLangChineseTraditional |
Traditional Chinese |
dbLangCyrillic |
Russian |
dbLangCzech |
Czech |
dbLangDutch |
Dutch |
dbLangGreek |
Greek |
dbLangHebrew |
Hebrew |
dbLangHungarian |
Hungarian |
dbLangIcelandic |
Icelandic |
dbLangJapanese |
Japanese |
dbLangKorean |
Korean |
dbLangNordic |
Nordic languages (Microsoft Jet database engine version 1.0 only) |
dbLangNorwDan |
Norwegian and Danish |
dbLangPolish |
Polish |
dbLangSlovenian |
Slovenian |
dbLangSpanish |
Traditional Spanish |
dbLangSwedFin |
Swedish and Finnish |
dbLangThai |
Thai |
dbLangTurkish |
Turkish |
You can use one or more of the following constants in the options argument to specify which version the data format should have and whether or not to encrypt the database.
Constant |
Description |
---|---|
dbEncrypt |
Creates an encrypted database. |
dbVersion10 |
Creates a database that uses the Microsoft Jet database engine version 1.0 file format. |
dbVersion11 |
Creates a database that uses the Microsoft Jet database engine version 1.1 file format. |
dbVersion20 |
Creates a database that uses the Microsoft Jet database engine version 2.0 file format. |
dbVersion30 |
Creates a database that uses the Microsoft Jet database engine version 3.0 file format (compatible with version 3.5). |
dbVersion40 |
Creates a database that uses the Microsoft Jet database engine version 4.0 file format. |
dbVersion120 |
Creates a database that uses the Microsoft Access database engine version 12.0 file format. |
If you omit the encryption constant, CreateDatabase creates an un-encrypted database.
Use the CreateDatabase method to create and open a new, empty database, and return the Database object. You must complete its structure and content by using additional DAO objects. If you want to make a partial or complete copy of an existing database, you can use the CompactDatabase method to make a copy that you can customize.
Example
This example uses CreateDatabase to create a new, encrypted Database object.
Sub CreateDatabaseX()
Dim wrkDefault As Workspace
Dim dbsNew As DATABASE
Dim prpLoop As Property
' Get default Workspace.
Set wrkDefault = DBEngine.Workspaces(0)
' Make sure there isn't already a file with the name of
' the new database.
If Dir("NewDB.mdb") <> "" Then Kill "NewDB.mdb"
' Create a new encrypted database with the specified
' collating order.
Set dbsNew = wrkDefault.CreateDatabase("NewDB.mdb", _
dbLangGeneral, dbEncrypt)
With dbsNew
Debug.Print "Properties of " & .Name
' Enumerate the Properties collection of the new
' Database object.
For Each prpLoop In .Properties
If prpLoop <> "" Then Debug.Print " " & _
prpLoop.Name & " = " & prpLoop
Next prpLoop
End With
dbsNew.Close
End Sub