- Home
·
- Miscellaneous
·
- This code will allow you to make primary key in vb6.0 which is connected with ms access.
This code will allow you to make primary key in vb6.0 which is connected with ms access.
This code will allow you to make primary key in vb6.0 which is connected with ms access.
Rate This code will allow you to make primary key in vb6.0 which is connected with ms access.
(1(1 Vote))
Dim db As Database
Dim tbl As TableDef
Dim fld As Field
Dim idx As Index
' Start by opening the database
Set db = CurrentDb()
' Create a tabledef object
Set tbl = db.CreateTableDef("TableName")
' Create a field; set its properties; add it to the tabledef
Set fld = tbl.CreateField("ID_Field", dbLong)
fld.OrdinalPosition = 1 ' set as first field
fld.Attributes = dbAutoIncrField 'make autonumber
tbl.Fields.Append fld ' add the field
' Create another; set its properties; add it to the tabledef
Set fld = tbl.CreateField("NextFieldName", dbText)
fld.OrdinalPosition = 2 ' set as second field
fld.Size = 50
fld.Required = True ' nulls not allowed
fld.AllowZeroLength = False
tbl.Fields.Append fld
' Make ID_Field the primary key
Set idx = tbl.CreateIndex("PrimaryKey")
idx.Primary = True
idx.Required = True
idx.Unique = True
' Add a field to the index
Set fld = idx.CreateField("ID_Field")
idx.Fields.Append fld
' Add the index to the tabledef
tbl.Indexes.Append idx
' Finally add table to the database
db.TableDefs.Append tbl
' And refresh the database window
RefreshDatabaseWindow
set idx=Nothing
set fld=Nothing
set tbl=Nothing
set db=Nothing
End Sub
This code will allow you to make primary key in vb6.0 which is connected with ms access. Comments
No comments yet — be the first to post one!
Post a Comment