VBA code asks for Macro Name

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am confused.

I am running Access 2002 SP3.

I have converted an Access 97 application for usage under 2002. I need to
write a new routine. I assume it will use DAO (since the original application
was written in 97 which uses DAO....right?)

I know enough to be dangerous...maybe very dangerous. I am using Balter's
*Access 97* book to find something that works and modify it.

When I create a command button on a form and import some *test* code (which
I just cut and pasted) to execute a window appears requesting a *Macro Name*.
Well there aren't any macros.

And I am totally clueless what I need to do or what I am doing wrong.

Any ideas?

TIA,
Bobby
 
Below is the code.

I simply created a new command button (cmdTest) and the cut and pasted in
the code example from the book.

When I run the code it asks for the the Macro Name....that is why I assumed
it is environmental


Private Sub cmdTest_Click()
Dim db As Database
Dim tbl As TableDef
Dim fld As Field
Dim idx As Index

Set db = CurrentDb()
' Create new TableDef.
Set tbl = db.CreateTableDef("tblFoods")
' Add field to Table Definition
Set fld = tbl.CreateField("FoodID", DB_TEXT, 5)
tbl.Fields.Append fld
Set fld = tbl.CreateField("Description", DB_TEXT, 25)
tbl.Fields.Append fld
Set fld = tbl.CreateField("Calories", DB_INTEGER)
tbl.Fields.Append fld
db.TableDefs.Append tbl
Set idx = tbl.CreateIndex("PrimaryKey")
Set fld = idx.CreateField("FoodID")
idx.Primary = True
idx.Unique = True
idx.Fields.Append fld
tbl.Indexes.Append idx
End Sub
 
OK...forget it....I was testing from the Visual Basic code window.

When I went to the actual form and cliicked on the button it worked fine.

Too much Visual Studio expectations...I guess.
 
Back
Top