• Relationship in remote db (Access 2000)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Relationship in remote db (Access 2000)

    Author
    Topic
    #389325

    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

    Viewing 0 reply threads
    Author
    Replies
    • #687067

      So what is the error you get, and on which line of the function does it occur?

      • #687107

        Thank you for your reply.I do not get any error,but the tables orders and order details are not linked in one to many relationship when i check it..I am puzzled since with the other function it works and i can see the links created.But in this case no error occrus but nothing is created

        Best regards

        • #687116

          You have:
          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

          Is the bolded code correct?

    Viewing 0 reply threads
    Reply To: Relationship in remote db (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: