This article shows you how to use Data Access Objects (DAO) in Microsoft
Access 2000 to create an Access 2.0 database, and how to copy entire tables from an Access 2000 database to the newly created Access 2.0 database. This technique allows you to share data with others who run Access 2.0.
Back to the top
NOTE: The sample code in this article uses Microsoft Data Access Objects. For this code to run properly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click
References on the
Tools menu in the Visual Basic Editor, and make sure that the
Microsoft DAO 3.6 Object Library check box is selected.
To create an Access 2.0 database and copy tables from the
current Access 2000 database, follow these steps:
| 1. | Start Access and open the sample database Northwind.mdb. |
| 2. | In the Database window, click Modules, and then click New.
|
| 3. | Type or paste the following procedure:
Public Function CreateDB()
Dim newdb As DAO.DATABASE, mydb As DAO.DATABASE
Dim dbname As String
Dim tdf As DAO.TableDef
'Set the path and name for the new database.
dbname = "C:\Program Files\Microsoft Office" _
& "\Office\Samples\Newdb.mdb"
'Create the new 2.0 database and close newdb.
Set newdb = DBEngine.Workspaces(0).CreateDatabase(dbname, _
dbLangGeneral, dbVersion20)
newdb.Close
'Export all non-system tables to the version 2.0 database.
Set mydb = CurrentDb()
For Each tdf In mydb.TableDefs
If (tdf.Attributes And dbSystemObject) = 0 Then
DoCmd.TransferDatabase acExport, "Microsoft Access", _
dbname, acTable, tdf.Name, tdf.Name
End If
Next tdf
End Function
|
| 4. | To test the function, type the following line in the Immediate window, and then press ENTER: ? CreateDB()
Note that the new version 2.0 database is created (in the location that you specified) and that all non-system tables in the current version
database are exported to the new version 2.0 database.
NOTE: You can export only tables to an Access 2.0 database; you
cannot export other database objects such as forms or reports. If you
try to export other objects, you receive the following error message:
Run-time error '7854':
You can't export database objects (except tables) from the
current version of Access to previous versions of
Access.
In addition, you cannot export tables from databases that have been
replicated because these tables have system-defined fields with a
data type of ReplicationID. Access 2.0 does not have a
ReplicationID data type. |
Back to the top
For more information about creating databases using DAO, in the Visual Basic Editor, click
Microsoft Visual Basic Help on the
Help menu, type
database properties in the Office Assistant or the Answer Wizard, and then click
Search to view the topic.
For more information about the Attributes property and the dbSystemObject constant, in the Visual Basic Editor, click
Microsoft Visual Basic Help on the
Help menu, type
object properties in the Office Assistant or the Answer Wizard, and then click
Search to view the topic.
Back to the top