VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This code will allow you to make primary key in vb6.0 which is connected with ms access.

by ISMAIL (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 22nd March 2008
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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.



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


Download this snippet    Add to My Saved Code

This code will allow you to make primary key in vb6.0 which is connected with ms access. Comments

No comments have been posted about This code will allow you to make primary key in vb6.0 which is connected with ms access.. Why not be the first to post a comment about This code will allow you to make primary key in vb6.0 which is connected with ms access..

Post your comment

Subject:
Message:
0/1000 characters