Hi. I can't seem to be able to create a simple table. Here's the code I got...
Sub CreateTable()
Dim db As Database
Dim tblR As TableDef
Dim fld As Field
Dim idx As Index
'Create a TableDef object
Set db = CurrentDb()
Set tblR = db.CreateTableDef("tblResult"
'Create a field, Set its properties
Set fld = tblR.CreateField("Hour", dbInteger)
fld.OrdinalPosition = 1
fld.Attributes = dbAutoIncrField
tblR.Fields.Append fld
'Creating more fields
... ...
... ...
'Create an index and set its properties
Set idx = tblR.CreateIndex("Primary Key"
idx.Primary = True
idx.Required = True
idx.Unique = True
'Add a field to the index
Set fld = idx.CreateField("Hour"
idx.Fields.Append fld
'Add the index to the TableDef
tblR.Indexes.Append idx
'Add the table to the database
db.TableDefs.Append tblR
'Refresh the Database Windsow
RefreshDatabaseWindow
End Sub
I get a run-time error at: db.TableDefs.Append tbR (second last line of code)
the msg says "run time error 3001, invalid argument"
can someone find the mistake please!
thanks.
josh
Sub CreateTable()
Dim db As Database
Dim tblR As TableDef
Dim fld As Field
Dim idx As Index
'Create a TableDef object
Set db = CurrentDb()
Set tblR = db.CreateTableDef("tblResult"
'Create a field, Set its properties
Set fld = tblR.CreateField("Hour", dbInteger)
fld.OrdinalPosition = 1
fld.Attributes = dbAutoIncrField
tblR.Fields.Append fld
'Creating more fields
... ...
... ...
'Create an index and set its properties
Set idx = tblR.CreateIndex("Primary Key"
idx.Primary = True
idx.Required = True
idx.Unique = True
'Add a field to the index
Set fld = idx.CreateField("Hour"
idx.Fields.Append fld
'Add the index to the TableDef
tblR.Indexes.Append idx
'Add the table to the database
db.TableDefs.Append tblR
'Refresh the Database Windsow
RefreshDatabaseWindow
End Sub
I get a run-time error at: db.TableDefs.Append tbR (second last line of code)
the msg says "run time error 3001, invalid argument"
can someone find the mistake please!
thanks.
josh