Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error: invalid outside procedure

Status
Not open for further replies.

jain747

Technical User
Apr 22, 2003
17
US
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")

'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
 
Hi,

I assume that this is a module. If so, then the code from the line "dim ws as workspace" onwards should be put inside a sub or function.
You can then execute the function or sub from elsewhere.

Thus:
Code:
Public sub SubName
<insert code here>
End Sub

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top