Databases Reference
In-Depth Information
an opened
Database
object, but the database has no structure or content at this
point.
To duplicate a database, you can use the
CompactDatabase
method of a
Workspace
object, specifying a different name for the compacted database.
•
A database cannot be deleted programmatically through DAO. To delete a
database programatically, use the
KILL
statement in VBA.
•
Example 15-1 creates a new database named
MoreBks.mdb
on the directory
c:/temp
and
then lists the tables that are contained in the database.
Example 15-1. A CreateDatabase method example
Sub
exaCreateDb( )
Dim dbNew As DATABASE
Dim tbl As TableDef
Set dbNew = CreateDatabase _
("c:\temp\MoreBks", dbLangGeneral)
For Each tbl In dbNew.TableDefs
Debug.Print tbl.Name
Next
dbNew.Close
End
Sub
The program in Example 15-1 displays the following list of tables:
MSysACEs
MSysObjects
MSysQueries
MSysRelationships
These tables are created by Microsoft Access for its own use.
15.2 Opening a Database
To open an existing database, use the
OpenDatabase
method of a
Workspace
object. The
syntax is:
Set
DatabaseVar
= [
WorkspaceVar
.]OpenDatabase _
(
DatabaseName
[,
exclusive
[,
read
-
only
[,
source
]]])
where
DatabaseName
is the name of an existing database. (As indicated by the square
brackets, the other parameters are optional.) For information about the optional
parameters, see the Access help system.