Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!

Creating relationships using VBA

Discussion in 'Information Technology' started by mohd21uk via AccessMonster.com, Jul 28, 2006.

  1. mohd21uk via AccessMonster.com

    Guest

    I have a table called tbl Status which has a field called Status and a table
    called tbl CN43 with a field called Status. I would like to link both the
    fields together using VBA code. I would be grateful if you could provide me
    the code to do this.

    Many Thanks,

    --
    Message posted via AccessMonster.com
    http://www.accessmonster.com/Uwe/Forums.aspx/access/200606/1
     
  2. Loading...

    Similar Threads Forum Date
    Canada Ottawa weighs creating ambassador for religious freedom Breaking News Oct 4, 2011
    India SGPC Accused of Creating a Row Breaking News Jan 20, 2011
    Pacific International Gathering of Young Sikhs Focuses on Creating Good Citizens Breaking News Jan 8, 2011
    Are We Creating New Devtas? Sikh Sikhi Sikhism Aug 21, 2009
    Sikh News Sharif warns against creating instability in Punjab (Express India) Breaking News Sep 19, 2008

  3. Allen Browne

    Allen Browne
    Expand Collapse
    Guest

    The code would be something like this:

    Dim db As DAO.Database
    Dim rel As DAO.Relation
    Dim fld As DAO.Field

    'Initialize
    Set db = CurrentDb()

    'Create a new relation.
    Set rel = db.CreateRelation("StatusCN43")

    'Define its properties.
    With rel
    'Specify the primary table.
    .Table = "tbl Status"
    'Specify the related table.
    .ForeignTable = "tbl CN43"
    'Specify attributes for cascading updates and deletes.
    .Attributes = dbRelationUpdateCascade + dbRelationDeleteCascade

    'Add the fields to the relation.
    'Field name in primary table.
    Set fld = .CreateField("Status")
    'Field name in related table.
    fld.ForeignName = "Status"
    'Append the field.
    .Fields.Append fld
    End With

    'Save the newly defined relation to the Relations collection.
    db.Relations.Append rel

    --
    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.

    "mohd21uk via AccessMonster.com" <u20517@uwe> wrote in message
    news:621b308278ce2@uwe...
    >I have a table called tbl Status which has a field called Status and a
    >table
    > called tbl CN43 with a field called Status. I would like to link both the
    > fields together using VBA code. I would be grateful if you could provide
    > me
    > the code to do this.
     

Share This Page