Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    2

    Unanswered: Please help me with figure out how to do this...

    I would like to link a field (primary key) of the parent table (1,2,3) to match the children in the child table. So if Joe Williams has two children, his unique id is 1 and then in the child table his first child is 1a and second child is 1b. The next parent would be 2 etc. And as I add new students can Access automatically link these fields to create the right ID?

    I've tried everything...

    THANK YOU!

  2. #2
    Join Date
    Aug 2003
    Location
    Bulgaria, Plovdiv
    Posts
    36
    Parents table
    ---------
    ParentID Long
    ParentName Text

    Childrens Table
    --------------
    ChildID - Long
    ParentID - Foreign Key to Parents Table
    ChildName - Text

    Let's have one record in Parents table
    ParentID=1 ParentName = "Joe Dow"

    Here is how we can add a child named "Malisha Ion" that is linked to "Joe Dow"
    '---------

    Dim conConnection As ADODB.Connection
    Dim StrSQL As String
    Dim iAffected As Integer

    Set conConnection = CurrentProject.Connection
    StrSQL = "INSERT INTO Childrens (ChildName,ParentID ) Values " _
    & "(" & "'" & "Malisha Ion" & "'" & _
    ", " & 1 & ");"

    conConnection.Execute StrSQL, iAffected, adExecuteNoRecords

  3. #3
    Join Date
    Jun 2009
    Posts
    2
    Thanks for your help. My only problem is that I was looking for an easy way to the link the tables without manually adding the parent ID to the child table. If I have 1000 parents I don't want to assign a number for each of them. Is there a way that the field will automatically populate by linking lastname and firstname? I tried this and when I run the query it's not coming out right.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •