Part | Description |
olddb | A String that identifies an existing, closed database. It can be a full path and file name, such as "C:\db1.mdb". If the file name has an extension, you must specify it. If your network supports it, you can also specify a network path, such as "\\server1\share1\dir1\db1.mdb". |
newdb | A String that is the file name (and path) of the compacted database that you're creating. You can also specify a network path. You can't use the newdb argument to specify the same database file as olddb. |
locale | Optional. A Variant that is a string expression that specifies a collating order for creating newdb, as specified in Settings. If you omit this argument, the locale of newdb is the same as olddb. |
You can also create a password for newdb by concatenating the password string (starting with ";pwd=") with a constant in the locale argument, like this: | |
dbLangSpanish & ";pwd=NewPassword" | |
If you want to use the same locale as olddb (the default value), but specify a new password, simply enter a password string for locale: | |
";pwd=NewPassword" | |
options | Optional. 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. |
password | Optional. A Variant that is a string expression containing a password, if the database is password protected. The string ";pwd=" must precede the actual password. If you include a password setting in locale, this setting is ignored. |
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 |
Constant | Collating order |
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 |
Constant | Description |
dbEncrypt | Encrypt the database while compacting. |
dbDecrypt | Decrypt the database while compacting. |
Constant | Description |
dbVersion10 | Creates a database that uses the Microsoft Jet database engine version 1.0 file format while compacting. |
dbVersion11 | Creates a database that uses the Microsoft Jet database engine version 1.1 file format while compacting. |
dbVersion20 | Creates a database that uses the Microsoft Jet database engine version 2.0 file format while compacting. |
dbVersion30 | Creates a database that uses the Microsoft Jet database engine version 3.0 file format (compatible with version 3.5) while compacting. |
Sub CompactDatabaseX()
Dim dbsNorthwind As Database
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
' Show the properties of the original database.
With dbsNorthwind
Debug.Print .Name & ", version " & .Version
Debug.Print " CollatingOrder = " & .CollatingOrder
.Close
End With
' Make sure there isn't already a file with the
' name of the compacted database.
If Dir("NwindKorean.mdb") <> "" Then Kill "NwindKorean.mdb"
' This statement creates a compact version of the
' Northwind database that uses a Korean language
' collating order.
DBEngine.CompactDatabase "Northwind.mdb",
"NwindKorean.mdb", dbLangKorean
Set dbsNorthwind = OpenDatabase("NwindKorean.mdb")
' Show the properties of the compacted database.
With dbsNorthwind
Debug.Print .Name & ", version " & .Version
Debug.Print " CollatingOrder = " & .CollatingOrder
.Close
End With
End Sub
This example uses the CompactDatabase method to change the version of a database. To run this code, you must have a Microsoft Jet version 1.1 database called Nwind11.mdb and you cannot use this code in a module belonging to Nwind11.mdb.
Sub CompactDatabaseX2()
Dim dbsNorthwind As Database
Dim prpLoop As Property
Set dbsNorthwind = OpenDatabase("Nwind11.mdb")
' Show the properties of the original database.
With dbsNorthwind
Debug.Print .Name & ", version " & .Version
Debug.Print " CollatingOrder = " & .CollatingOrder
.Close
End With
' Make sure there isn't already a file with the
' name of the compacted database.
If Dir("Nwind20.mdb") <> "" Then Kill "Nwind20.mdb"
' This statement creates a compact and encrypted
' Microsoft Jet 2.0 version of a Microsoft Jet version
' 1.1 database.
DBEngine.CompactDatabase "Nwind11.mdb", _
"Nwind20.mdb", , dbEncrypt + dbVersion20
Set dbsNorthwind = OpenDatabase("Nwind20.mdb")
' Show the properties of the compacted database.
With dbsNorthwind
Debug.Print .Name & ", version " & .Version
For Each prpLoop In .Properties
On Error Resume Next
If prpLoop <> "" Then Debug.Print " " & _
prpLoop.Name & " = " & prpLoop
On Error GoTo 0
Next prpLoop
.Close
End With
End Sub