I am using the following code to establish a relationship between tblCompany and MainTable. tblCompany is on the "One" side with a primary key called Comp_Id and MainTable is on the "many" side and has fk_Comp_Id as its linking field. When I run this code I get the error message "User defined type not defined". This is my first attempt using the ADOX model so any help would be appreciated.
Private Sub Command1_Click()
Dim tbl As ADOX.Table
Dim fk As ADOX.Key
Dim cat As ADOX.Catalog
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables("tblCompany")
Set fk = New ADOX.Key
With fk
.Name = "Comp_Id"
.Type = adKeyForeign
.RelatedTable = "MainTable"
.Columns.Append "fk_Comp_Id"
.Columns("fk_Comp_Id").RelatedColumn = "fk_Comp_Id"
End With
tbl.Keys.Append fk
Set cat = Nothing
Set tbl = Nothing
Set fk = Nothing
End Sub
Private Sub Command1_Click()
Dim tbl As ADOX.Table
Dim fk As ADOX.Key
Dim cat As ADOX.Catalog
Set cat = New ADOX.Catalog
cat.ActiveConnection = CurrentProject.Connection
Set tbl = cat.Tables("tblCompany")
Set fk = New ADOX.Key
With fk
.Name = "Comp_Id"
.Type = adKeyForeign
.RelatedTable = "MainTable"
.Columns.Append "fk_Comp_Id"
.Columns("fk_Comp_Id").RelatedColumn = "fk_Comp_Id"
End With
tbl.Keys.Append fk
Set cat = Nothing
Set tbl = Nothing
Set fk = Nothing
End Sub