I'm not sure why I get an error (invaliv outside procedure) on the line
Set ws = DBEngine.Workspaces(0). maybe someone can help me out. thanks.
' Option Compare Database
' Data Definition Language example
' Declare varaibles of the required types
Dim ws As Workspace
Dim dbLibrary As Database
Dim tblBooks As TableDef
Dim fldBooks As Field
Dim idxBooks As Index
' Use the default workspace, called Workspaces(0)
Set ws = DBEngine.Workspaces(0)
'Create a new database named LIBRARY
'in the default Workspace
Set dbLibrary = _
ws.CreateDatabase("c:\library.mbd", _
dbLangGeneral)
dbLibrary.Name = "LIBRARY"
' Create a new table called BOOKS
Set tblBooks = dbLibrary.CreateTableDef("BOOKS"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
'Define ISBN field and append to the
'table's Fields collection
Set fldBooks = tblBooks.CreateField("ISBN", dbText)
fldBooks.Size = 13
tblBooks.Fields.Append fldBooks
'Define Title field and append to the
'table's Fields collection
Set fldBooks = tblBooks.CreateField("Title", dbText)
fldBooks.Size = 100
tblBooks.Fields.Append fldBooks
' Add the table to the db's Tables collection
dbLibrary.TableDefs.Append tblBooks
'Create an index
Set idxBooks = tblBooks.CreateIndex("ISBNIdx"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
idxBooks.Unique = False
'Indices need their own fields
Set fldBooks = idxBooks.CreateField("ISBN"![Wink ;) ;)](data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)
'Append to the proper collections
idxBooks.Fields.Append fldBooks
tblBooks.Indexes.Append idxBooks
Set ws = DBEngine.Workspaces(0). maybe someone can help me out. thanks.
' Option Compare Database
' Data Definition Language example
' Declare varaibles of the required types
Dim ws As Workspace
Dim dbLibrary As Database
Dim tblBooks As TableDef
Dim fldBooks As Field
Dim idxBooks As Index
' Use the default workspace, called Workspaces(0)
Set ws = DBEngine.Workspaces(0)
'Create a new database named LIBRARY
'in the default Workspace
Set dbLibrary = _
ws.CreateDatabase("c:\library.mbd", _
dbLangGeneral)
dbLibrary.Name = "LIBRARY"
' Create a new table called BOOKS
Set tblBooks = dbLibrary.CreateTableDef("BOOKS"
'Define ISBN field and append to the
'table's Fields collection
Set fldBooks = tblBooks.CreateField("ISBN", dbText)
fldBooks.Size = 13
tblBooks.Fields.Append fldBooks
'Define Title field and append to the
'table's Fields collection
Set fldBooks = tblBooks.CreateField("Title", dbText)
fldBooks.Size = 100
tblBooks.Fields.Append fldBooks
' Add the table to the db's Tables collection
dbLibrary.TableDefs.Append tblBooks
'Create an index
Set idxBooks = tblBooks.CreateIndex("ISBNIdx"
idxBooks.Unique = False
'Indices need their own fields
Set fldBooks = idxBooks.CreateField("ISBN"
'Append to the proper collections
idxBooks.Fields.Append fldBooks
tblBooks.Indexes.Append idxBooks