Create a relationship in code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yitzak

    Create a relationship in code

    Hi after adding a field to a table through VBA

    How do I create a foreign key constraint/relationship between this
    field and a field in another table - and enforce referential integrity
    through VBA code.

    Thanks
  • Tom van Stiphout

    #2
    Re: Create a relationship in code

    On Thu, 21 Feb 2008 05:25:22 -0800 (PST), Yitzak
    <terryshamir@ya hoo.co.ukwrote:

    Check out the CreateRelation method in the help file.
    -Tom.

    >Hi after adding a field to a table through VBA
    >
    >How do I create a foreign key constraint/relationship between this
    >field and a field in another table - and enforce referential integrity
    >through VBA code.
    >
    >Thanks

    Comment

    • Allen Browne

      #3
      Re: Create a relationship in code

      See:


      Shows how to create the relationship and set its properties and attributes,
      and the add the fields involved in the relationship. It's all fairly
      self-explanatory, provided you understand that CreateField in this context
      means "add the field to the relationship", i.e. it is not actually creating
      a new field in the table.

      There are other ways, such as using CONSTRAINT in a DDL query.

      --
      Allen Browne - Microsoft MVP. Perth, Western Australia
      Tips for Access users - http://allenbrowne.com/tips.html
      Reply to group, rather than allenbrowne at mvps dot org.

      "Yitzak" <terryshamir@ya hoo.co.ukwrote in message
      news:c9d2d6ea-8cbf-4954-abc4-594fa8e5d3c1@28 g2000hsw.google groups.com...
      Hi after adding a field to a table through VBA
      >
      How do I create a foreign key constraint/relationship between this
      field and a field in another table - and enforce referential integrity
      through VBA code.
      >
      Thanks

      Comment

      • Yitzak

        #4
        Re: Create a relationship in code

        On 21 Feb, 13:47, "Allen Browne" <AllenBro...@Se eSig.Invalidwro te:
        See:

        >
        Shows how to create the relationship and set its properties and attributes,
        and the add the fields involved in the relationship. It's all fairly
        self-explanatory, provided you understand that CreateField in this context
        means "add the field to the relationship", i.e. it is not actually creating
        a new field in the table.
        >
        There are other ways, such as using CONSTRAINT in a DDL query.
        >
        --
        Allen Browne - Microsoft MVP. Perth, Western Australia
        Tips for Access users -http://allenbrowne.com/tips.html
        Reply to group, rather than allenbrowne at mvps dot org.
        >
        "Yitzak" <terrysha...@ya hoo.co.ukwrote in message
        >
        news:c9d2d6ea-8cbf-4954-abc4-594fa8e5d3c1@28 g2000hsw.google groups.com...
        >
        Hi after adding a field to a table through VBA
        >
        How do I create a foreign key constraint/relationship between this
        field and a field in another table - and enforce referential integrity
        through VBA code.
        >
        Thanks
        Thanks guys whats this DDL I guess Data Defintion language

        link to an access example for DDL?

        Comment

        • Allen Browne

          #5
          Re: Create a relationship in code

          Here's a DDL example that creates a Contractor table, a Booking table, and
          sets a relationship wihht cascade-to-null:
          VBA code using DDL statements (Data Definition Language - part of SQL) in Microsoft Access.


          --
          Allen Browne - Microsoft MVP. Perth, Western Australia
          Tips for Access users - http://allenbrowne.com/tips.html
          Reply to group, rather than allenbrowne at mvps dot org.

          "Yitzak" <terryshamir@ya hoo.co.ukwrote in message
          news:573dffa6-d400-47c7-9af8-48938ec5d423@p4 3g2000hsc.googl egroups.com...
          >
          Thanks guys whats this DDL I guess Data Defintion language
          >
          link to an access example for DDL?

          Comment

          • Yitzak

            #6
            Re: Create a relationship in code

            On 21 Feb, 15:49, "Allen Browne" <AllenBro...@Se eSig.Invalidwro te:
            Here's a DDL example that creates a Contractor table, a Booking table, and
            sets a relationship wihht cascade-to-null:
            VBA code using DDL statements (Data Definition Language - part of SQL) in Microsoft Access.

            >
            --
            Allen Browne - Microsoft MVP. Perth, Western Australia
            Tips for Access users -http://allenbrowne.com/tips.html
            Reply to group, rather than allenbrowne at mvps dot org.
            >
            "Yitzak" <terrysha...@ya hoo.co.ukwrote in message
            >
            news:573dffa6-d400-47c7-9af8-48938ec5d423@p4 3g2000hsc.googl egroups.com...
            >
            >
            >
            Thanks guys whats this DDL I guess Data Defintion language
            >
            link to an access example for DDL?
            Thanks Allen - just like MSSQL T-Sql

            had no idea you could do this..

            Comment

            Working...