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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Creating Table

Status
Not open for further replies.

Joshy

Programmer
Mar 8, 2001
14
CA


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

Here's your prob': Set fld = tblR.CreateField("Hour", dbInteger)

Needs to be:Set fld = tblR.CreateField("Hour", dbLong)

Thats it!
Gord
ghubbell@total.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top