Linking Child and Parent Fields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aharding
    New Member
    • Sep 2006
    • 22

    Linking Child and Parent Fields

    Hello!

    I have a form that opens with the click of a toggle button on another form. I would like to link the child and parent fields of the forms for data input but am not experienced enough with codes to write it myself. Can someone help me with this?

    Parent fields are
    [Forms]![Add New Subfunctions]![CCN]
    [Forms]![Add New Subfunctions]![UIC]
    [Forms]![Add New Subfunctions]![Sub #]
    [Forms]![Add New Subfunctions]![Sub CCN]

    Child fields are
    [Forms]![Algorithm YES]![CCN]
    [Forms]![Algorithm YES]![UIC]
    [Forms]![Algorithm YES]![Sub #]
    [Forms]![Algorithm YES]![CCN Subfunction_Sub CCN]

    I already have an OnOpen macro that opens to a new record. Any help would be appreciated. Thanks.
  • PEB
    Recognized Expert Top Contributor
    • Aug 2006
    • 1418

    #2
    Hey man!

    Do you have relationships between your tables?

    If Yes... Pls use the Form Wizard! Choose Main Sub Form Wizard and fill in... There is a possibility just like you want...

    It will create instaed you!

    :)

    And then you' ll see the code!

    :)

    Comment

    • aharding
      New Member
      • Sep 2006
      • 22

      #3
      Originally posted by PEB
      Hey man!

      Do you have relationships between your tables?

      If Yes... Pls use the Form Wizard! Choose Main Sub Form Wizard and fill in... There is a possibility just like you want...

      It will create instaed you!

      :)

      And then you' ll see the code!

      :)
      Will I still be able to open the form by selecting one of the toggle buttons? I didn't create a subform becuase it was actually a separate form that opened on a Yes/No toggle. How do I do this....

      Comment

      • PEB
        Recognized Expert Top Contributor
        • Aug 2006
        • 1418

        #4
        In fact this wizard can create 2 or more separate forms linked between them.
        When U press the bouton for the form when the respective form is open the bouton stay pressed! When you press it an other time it closes the form!

        Is this something convenable for You?

        Comment

        • aharding
          New Member
          • Sep 2006
          • 22

          #5
          Originally posted by PEB
          In fact this wizard can create 2 or more separate forms linked between them.
          When U press the bouton for the form when the respective form is open the bouton stay pressed! When you press it an other time it closes the form!

          Is this something convenable for You?
          Well that sounds perfect....!
          When using the wizard...how do I make the subform show up as a button? I just need them to be able to choose becuase there are different forms based on each choice.

          Comment

          • PEB
            Recognized Expert Top Contributor
            • Aug 2006
            • 1418

            #6
            In fact it doesn't appears subform, but a linked form to the main one...

            In fact you want a check bouton... When it is checked on of the forms is opened when is not checked the other one is opened doesn't it?

            Comment

            • aharding
              New Member
              • Sep 2006
              • 22

              #7
              Originally posted by PEB
              In fact it doesn't appears subform, but a linked form to the main one...

              In fact you want a check bouton... When it is checked on of the forms is opened when is not checked the other one is opened doesn't it?
              Huh? I think I am confused now.

              Previously I had three forms....One main form with information and a choice of Yes/No. When Yes was selected a form popped up for data entry. When No was selected a different form popped up for data entry. The problem was there was no link to the parent form so the data entered was not going to the tables.

              When I used the subform wizard, it insered the form I chose into the main form. There is no button, it is just in the main form always.

              I need to still have only the main form show with the choice of Yes/No to open these subforms.

              You mention boxes for this but my subforms are simply always on the main form. I would like the linked subforms but don't know how to do that.

              Comment

              • PEB
                Recognized Expert Top Contributor
                • Aug 2006
                • 1418

                #8
                Ok...

                My idea is to get the linking code from the Wizard, but maybe will be more simple to give you it here..

                This is the code generated by my wizard for
                main Form: Objects
                sub Form: Object_info

                Code:
                Option Compare Database
                Option Explicit
                
                Sub Form_Current()
                On Error GoTo Form_Current_Err
                
                    If ChildFormIsOpen() Then FilterChildForm
                
                Form_Current_Exit:
                    Exit Sub
                
                Form_Current_Err:
                    MsgBox Error$
                    Resume Form_Current_Exit
                
                End Sub
                Sub ToggleLink_Click() 'the sub for the bouton
                On Error GoTo ToggleLink_Click_Err
                default_object_value = Me.[ID_obj]
                    If ChildFormIsOpen() Then
                        CloseChildForm
                    Else
                        OpenChildForm
                        FilterChildForm
                    End If
                
                ToggleLink_Click_Exit:
                    Exit Sub
                
                ToggleLink_Click_Err:
                    MsgBox Error$
                    Resume ToggleLink_Click_Exit
                
                End Sub
                Private Sub FilterChildForm() 'Filters the sub form by the specified field
                
                    If Me.NewRecord Then
                        Forms![Object_info].DataEntry = True
                    Else
                        Forms![Object_info].Filter = "[ID_obj] = " & Me.[ID_obj]
                        Forms![Object_info].FilterOn = True
                    End If
                
                End Sub
                Private Sub OpenChildForm()
                
                    DoCmd.OpenForm "Object_info", acFormDS
                    If Not Me.[ToggleLink] Then Me![ToggleLink] = True
                
                End Sub
                Private Sub CloseChildForm()
                
                    DoCmd.Close acForm, "Object_info"
                    If Me![ToggleLink] Then Me![ToggleLink] = False
                
                End Sub
                Private Function ChildFormIsOpen()
                
                    ChildFormIsOpen = (SysCmd(acSysCmdGetObjectState, acForm, "Object_info") And acObjStateOpen) <> False
                
                End Function

                So to adapt this code to your Forms can you give me the names of your forms and their respective fields?

                And also the name of your toggle bouton?

                :)

                Comment

                Working...