×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Creating Table

Creating Table

Creating Table

(OP)


                         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

RE: Creating Table

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close