Linking records in two tables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luciegiles
    New Member
    • Oct 2007
    • 56

    Linking records in two tables

    I have 2 tables, tblParticipantD etails and tblPreCourseQ - both have ParticipantID in them and this links the tables in relationships. ParticipantID is the primary key (and an autonumber) in tblParticipantD etails and is a number (long integer) in tblPreCourseQ. I want the ParticipantID to update in tblPreCourseQ with the same number as assigned by the autonumber ParticpantID in tblParticpantDe tails. Data is entered via forms (frmParticpantD etails and frmPreCourseQ - source is tables as above) - frmPreCourseQ is opened from a command button on frmParticpantDe tails using a macro. Is there anyway I can have ParticpantID fill in frm and tblPreCourseQ when a new record is opened from frmParticpantDe tails?

    I know I could use a subform but don't really want to do this as I have 3 instances where I want to do this and don't want to put everything in one table.

    thanks
  • Megalog
    Recognized Expert Contributor
    • Sep 2007
    • 378

    #2
    In the Open event for the form that is bound to tblPreCourseQ (frmPreCourseQ) , you can do the following:

    Code:
    On Error Resume Next
    If Me.newrecord then
        Me.txtParticipantID = [Forms]![frmParticipantDetails].[txtParticipantID]
    End If

    Comment

    • luciegiles
      New Member
      • Oct 2007
      • 56

      #3
      What do you mean by Open event?

      Comment

      • luciegiles
        New Member
        • Oct 2007
        • 56

        #4
        No problem - done it as follows
        Code:
        Private Sub Form_Load()
        
        On Error Resume Next
        If Me.NewRecord Then
            Me.ParticipantID = [Forms]![frmParticipantDetails].[ParticipantID]
        End If
        
        End Sub
        thanks for your help

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32645

          #5
          To avoid setting the form as dirty (when it thinks that changes have been made and need to be either saved or discarded) I would suggest rather to set the Default property to the value required rather than the Value property.

          Comment

          • Megalog
            Recognized Expert Contributor
            • Sep 2007
            • 378

            #6
            Yeah I meant Load event.. The coffee hasnt kicked in yet this morning =)

            That code should work fine as long as the frmParticipantD etails form is always open whenever frmPreCourseQ is loaded.

            Comment

            Working...