I am very puzzled why one of my functions of creating relationships is working excellent, this is the function called LinkCallsCustomers
and the other function built in exactly the same way, does not work this is the function LinkOrdersToOrderDetails.
Is it possible that i have a mistake somewhere in my second function,and is there another way to try ?
Below are my two functions
Public Function LinkCallsCustomers()
On Error Resume Next
Dim wsp As DAO.Workspace
Dim StrPassword As String
StrPassword = “secret”
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set wsp = DAO.DBEngine.Workspaces(0)
Dim dbs As DAO.Database
Dim rel As DAO.Relation
Dim tdf1 As DAO.TableDef
Dim tdf2 As DAO.TableDef
Set dbs = wsp.OpenDatabase(“C:BEstoreBE.mdb”, False, False,
“;PWD=” & StrPassword)
With dbs
Set tdf1 = .TableDefs!customers
Set tdf2 = .TableDefs!CallsCustomers
Set rel = .CreateRelation(“CustomerIDRelationship”, tdf1.Name,
tdf2.Name, dbRelationUpdateCascade)
rel.Fields.Append rel.CreateField(“CustomerID”)
rel.Fields!Customerid.ForeignName = “CustomerID”
.Relations.Append rel
.Close
End With
End Function
==============================
Public Functions LinkOrdersToOrderDetails()
‘ links the tables orders and [order details]
On Error Resume Next
Dim wsp As DAO.Workspace
Dim StrPassword As String
StrPassword = “secret”
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Set wsp = DAO.DBEngine.Workspaces(0)
Dim dbs As DAO.Database
Dim rel As DAO.Relation
Dim tdf1 As DAO.TableDef
Dim tdf2 As DAO.TableDef
Set dbs = wsp.OpenDatabase(“C:BEstoreBE.mdb”, False, False,
“;PWD=” & StrPassword)
With dbs
Set tdf1 = .TableDefs!orders
Set tdf2 = .TableDefs![order details]
Set rel = .CreateRelation(“orderIDRelationship”, tdf1.Name,
tdf2.Name, dbRelationUpdateCascade)
rel.Fields.Append rel.CreateField(“orderID”)
rel.Fields!Customerid.ForeignName = “orderID”
.Relations.Append rel
.Close
End With
End Function