ID: Q141886
The information in this article applies to:
Moderate: Requires basic macro, coding, and interoperability skills.
This article shows you how to use Data Access Objects (DAO) in Microsoft Access 95 or 97 to create a Microsoft Access 2.0 database and how to copy entire tables from a Microsoft Access 95 or 97 database to the newly created Microsoft Access 2.0 database. This technique enables you to share data with others who run Microsoft Access 2.0.
This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.
To create a Microsoft Access 2.0 database and copy tables from the current Microsoft Access 95 or 97 database, follow these steps:
1. Create a new module.
2. Type the following procedure:
Public Function CreateDB()
Dim newdb As DATABASE, mydb As DATABASE
Dim dbname As String
Dim tdf As TableDef
'Set the path and name for the new database.
dbname = "c:\msoffice\access\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
3. To test the function, type the following line in the Debug window,
and then press ENTER.
? CreateDB()
Note that the new version 2.0 database is created (in the location you
specified) and that all nonsystem tables in the current version
database are exported to the new version 2.0 database.
NOTE: You can export only tables to a Microsoft 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:
Run-time error '7854':
You can't export database objects (except tables) from the
current version of Microsoft Access to previous versions of
Microsoft 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. Microsoft Access 2.0 does not have a
ReplicationID data type.
For more information about creating databases using DAO, search for "CreateDatabase," and then "CreateDatabase method" using the Microsoft Access 97 Help Index.
For more information about the Attributes property and the dbSystemObject constant, search for "Attributes," and then "Attributes property" using the Microsoft Access 97 Help Index.
Additional query words:
Keywords : kbprg MdlDao
Version : 7.0 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto
Last Reviewed: November 21, 1998