Search Tools Links Login

Create Access Table in VB


Visual Basic 6, or VB Classic

Allows the programmer to create an MS Access table in Visual Basic where the primary key's field data type is set to AutoNumber. It is not like creating the primary key field in Access where you can select AutoNumber date type. In VB 5 and 6 you can't request AutoNumber for a field type in the SQL Create Table string, it does not exist. So to create a table in VB where primary key's numeric field type will be AutoNumber, you have to do it the way the included source code shows. Hope this helps.

Original Author: unknown

Inputs

None.

Assumptions

None.

Returns

None.

Side Effects

None.

API Declarations

None.

Code

Private Sub Creat_Table()
Dim stSQLstr As String
Dim dbs As Database
stSQLstr = "CREATE TABLE NameTbl (NameID COUNTER CONSTRAINT PrimaryKey PRIMARY KEY, FirstName Text (15), LastName Text (20));"
  Set dbs = OpenDatabase("c: estDemo.mdb")
  dbs.Execute stSQLstr
  dbs.Close
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 103 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.