vipersmind
it can't be!
- Local time
- Tomorrow, 07:29
- Joined
- Dec 26, 2002
- Messages
- 82
Hi
I am trying to create table defs for a new table called tblMainAssay and would like to know if I can create 2 primary keys.
I know I can do this in the relationships window but not sure how to insert it into the vbCode.
I want HoleID and Depth_From to be the P.Keys.
I know it goes in the red section somewhere somehow.
There is also vbCode which follows this to make the relation between tblMainAssay and the existing tables.
Thanks
Cress
I am trying to create table defs for a new table called tblMainAssay and would like to know if I can create 2 primary keys.
I know I can do this in the relationships window but not sure how to insert it into the vbCode.
I want HoleID and Depth_From to be the P.Keys.
I know it goes in the red section somewhere somehow.
Code:
Function Make_tblMAINASSAY()
Dim db As Database
Dim tbl As TableDef
Dim fld As Field
Dim idx As Index
Dim errcode As ErrObject
'create references to the database
Set db = CurrentDb()
' specify what to call the new table
Set tbl = db.CreateTableDef("tblMainAssay")
' create the field references for the new table
Set fld = tbl.CreateField("HoleID", dbText, 20)
tbl.Fields.Append fld
Set fld = tbl.CreateField("Depth_From", dbSingle, 10)
tbl.Fields.Append fld
Set fld = tbl.CreateField("Depth_To", dbSingle, 10)
tbl.Fields.Append fld
Set fld = tbl.CreateField("SampleID", dbText, 10)
tbl.Fields.Append fld
Set fld = tbl.CreateField("AU1", dbSingle, 10)
tbl.Fields.Append fld
Set fld = tbl.CreateField("Matched", dbText, 10)
tbl.Fields.Append fld
' append the new fields to the table
db.TableDefs.Append tbl
' create a primary key index
[COLOR=red]Set idx = tbl.CreateIndex("PrimaryKey")
Set fld = idx.CreateField("HoleID")
idx.Primary = True
idx.Unique = True
idx.Fields.Append fld
tbl.Indexes.Append idx[/COLOR]
Call Make_tblMainCollar ' call the next funtion
End Function
There is also vbCode which follows this to make the relation between tblMainAssay and the existing tables.
Thanks
Cress