APPEND 語法
ADO
Sub CreateRelation()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim fk As ADOX.Key
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables("tblPeople")
Set fk = New ADOX.Key
fk.Name = "eopleFood"
fk.Type = adKeyForeign
fk.RelatedTable = "tblFoods"
fk.Columns.Append "FoodId"
fk.Columns("FoodID").RelatedColumn = "FoodID"
tbl.Keys.Append fk
Set cat = Nothing
Set tbl = Nothing
Set fk = Nothing
End Sub
DOA
Sub CreateRelation()
Dim db As Database
Dim rel As Relation
Dim fld As Field
Set db = CurrentDb
Set rel = db.CreateRelation()
With rel
.Name = "eopleFood"
.Table = "tblFoods"
.ForeignTable = "tblPeople"
.Attributes = dbRelationDeleteCascade
End With
Set fld = rel.CreateField("FoodID")
fld.ForeignName = "FoodID"
rel.Fields.Append fld
db.Relations.Append rel
End Sub
[此贴子已经被作者于2004-1-29 20:19:37编辑过]
|