How to Display Subform Value on the Main Form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MNNovice
    Contributor
    • Aug 2008
    • 418

    How to Display Subform Value on the Main Form

    I am trying to display a value from the sub form on to the main form. It's not a calculated data, just plain text.

    This is what I attempted without success.

    1. Created a text box called "Hero" within the subform [sfrmItemsCast] footer.
    2. In its control source I added this function:
    =iif(([icrSort] = 1,[iccID]),"")
    3. Created another text box on the main form and added this in its control source:

    =[sfrmItemsCast].Form![Hero]

    But I am getting this error message: #Name? I should mention that icrSort is a text field.

    My goal is to display the hero's name in a fancy font up on the main form.

    Can anyone please help me with this problem? Thanks a lot.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by MNNovice
    I am trying to display a value from the sub form on to the main form. It's not a calculated data, just plain text.

    This is what I attempted without success.

    1. Created a text box called "Hero" within the subform [sfrmItemsCast] footer.
    2. In its control source I added this function:
    =iif(([icrSort] = 1,[iccID]),"")
    3. Created another text box on the main form and added this in its control source:

    =[sfrmItemsCast].Form![Hero]

    But I am getting this error message: #Name? I should mention that icrSort is a text field.

    My goal is to display the hero's name in a fancy font up on the main form.

    Can anyone please help me with this problem? Thanks a lot.
    Try this in the Control Source of the Text Box in the Main Form:
    Code:
    =IIf(Forms!<Form Name>![sfrmItemsCast].[Form]![icrSort]="1",Forms!<Form Name>![sfrmItemsCast].[Form]![iccID],"")

    Comment

    • MNNovice
      Contributor
      • Aug 2008
      • 418

      #3
      Originally posted by ADezii
      Try this in the Control Source of the Text Box in the Main Form:
      Code:
      =IIf(Forms!<Form Name>![sfrmItemsCast].[Form]![icrSort]="1",Forms!<Form Name>![sfrmItemsCast].[Form]![iccID],"")
      Adezeii:

      I modified the code to match names of my forms. But I am getting this "invalid syntax" error message that reads: "You have entered a comma without a preceding value or identifier"

      Code:
      =IIf(Forms!<fItems>![sfItemsCast].[Form]![icrSort]="1", Forms!<fItems>![sfItemsCast].[Form]![iccID], "")
      Thanks for looking into my problem. M

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        Originally posted by MNNovice
        Adezeii:

        I modified the code to match names of my forms. But I am getting this "invalid syntax" error message that reads: "You have entered a comma without a preceding value or identifier"

        Code:
        =IIf(Forms!<fItems>![sfItemsCast].[Form]![icrSort]="1", Forms!<fItems>![sfItemsCast].[Form]![iccID], "")
        Thanks for looking into my problem. M
        Any chance of Uploading the Database?

        Comment

        • MNNovice
          Contributor
          • Aug 2008
          • 418

          #5
          Originally posted by ADezii
          Any chance of Uploading the Database?
          Certainly. Please see the attached.

          Main form: fItems
          Sub form: sfItemsCast

          I am trying to display names of the main characters (1 and 2) on fItems. Currently it's showing as "#Name?"

          Thanks for your time and effort.
          Last edited by NeoPa; Jun 8 '10, 10:07 AM. Reason: Member requested removal of attached db.

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by MNNovice
            Certainly. Please see the attached.

            Main form: fItems
            Sub form: sfItemsCast

            I am trying to display names of the main characters (1 and 2) on fItems. Currently it's showing as "#Name?"

            Thanks for your time and effort.
            It appears to me, that what you are requesting can be accomplished via the Current(0 Event of the sfItemsCast Sub-Form. Delete the Control Sources for the Tetxt Boxes on the Main Form, then Copy-and-Paste this Code into the Current Event of the Sub-Form:
            Code:
            Private Sub Form_Current()
            'Heroine Text Box in Main Form
            If Me![icrSort] = 1 Then
              Forms!fItems![Text51] = Me![iccID]
            Else
              Forms!fItems![Text51] = ""
            End If
            
            'Hero Text Box in Main Form
            If Me![icrSort] = 2 Then
              Forms!fItems![Text52] = Me.[iccID]
            Else
              Forms!fItems![Text52] = ""
            End If
            End Sub

            Comment

            • MNNovice
              Contributor
              • Aug 2008
              • 418

              #7
              Originally posted by ADezii
              It appears to me, that what you are requesting can be accomplished via the Current(0 Event of the sfItemsCast Sub-Form. Delete the Control Sources for the Tetxt Boxes on the Main Form, then Copy-and-Paste this Code into the Current Event of the Sub-Form:
              Code:
              Private Sub Form_Current()
              'Heroine Text Box in Main Form
              If Me![icrSort] = 1 Then
                Forms!fItems![Text51] = Me![iccID]
              Else
                Forms!fItems![Text51] = ""
              End If
              
              'Hero Text Box in Main Form
              If Me![icrSort] = 2 Then
                Forms!fItems![Text52] = Me.[iccID]
              Else
                Forms!fItems![Text52] = ""
              End If
              End Sub
              ADezii:

              Sorry but it didn't work. I get blanks on fItems.

              As suggested I made the two text boxes on fItems "Unbound".

              Added the following codes on Current of the sfItemsCast:
              Code:
              Private Sub Form_Current()
              
              'Heroine Text Box in Main Form
              If Me![icrSort] = 1 Then
              Forms!fItems![Heroine] = Me![iccID]
              Else
              
              Forms!fItems![Heroine] = ""
              
              End If
              
              'Hero Text Box in Main Form
              If Me![icrSort] = 2 Then
              Forms!fItems![Hero] = Me.[iccID]
              Else
              Forms!fItems![Hero] = ""
              End If
              
              
              End Sub
              I have replaced Text51 and Text52 with "Hero" and Heroine respectively. What am I doing wrong? I didn't get any error message but the unbound text boxes on fItems does not even display although the visible is set to YES.

              Thanks.

              Comment

              • ADezii
                Recognized Expert Expert
                • Apr 2006
                • 8834

                #8
                Originally posted by MNNovice
                ADezii:

                Sorry but it didn't work. I get blanks on fItems.

                As suggested I made the two text boxes on fItems "Unbound".

                Added the following codes on Current of the sfItemsCast:
                Code:
                Private Sub Form_Current()
                
                'Heroine Text Box in Main Form
                If Me![icrSort] = 1 Then
                Forms!fItems![Heroine] = Me![iccID]
                Else
                
                Forms!fItems![Heroine] = ""
                
                End If
                
                'Hero Text Box in Main Form
                If Me![icrSort] = 2 Then
                Forms!fItems![Hero] = Me.[iccID]
                Else
                Forms!fItems![Hero] = ""
                End If
                
                
                End Sub
                I have replaced Text51 and Text52 with "Hero" and Heroine respectively. What am I doing wrong? I didn't get any error message but the unbound text boxes on fItems does not even display although the visible is set to YES.

                Thanks.
                Text51 and Text 52 remain the same, and do not change.

                Comment

                • MNNovice
                  Contributor
                  • Aug 2008
                  • 418

                  #9
                  Originally posted by ADezii
                  Text51 and Text 52 remain the same, and do not change.
                  Even though on sfItems Footer, I changed the names of these two text boxes (Text51 to Heroine and Text52 to Hero)?

                  Comment

                  • ADezii
                    Recognized Expert Expert
                    • Apr 2006
                    • 8834

                    #10
                    Originally posted by MNNovice
                    Even though on sfItems Footer, I changed the names of these two text boxes (Text51 to Heroine and Text52 to Hero)?
                    I am referring to the Text Boxes on the Main Form, as per the Attachment:
                    Attached Files

                    Comment

                    • MNNovice
                      Contributor
                      • Aug 2008
                      • 418

                      #11
                      Originally posted by MNNovice
                      Even though on sfItems Footer, I changed the names of these two text boxes (Text51 to Heroine and Text52 to Hero)?
                      Okay. I see what you mean. But why no names is being displayed on the main form? Why those two text boxes do not even show up? On record no. 1, it should read as "Suchitra Sen" and "Uttam Kumar" for example. But they remain blank and invisible. Why is that?

                      Comment

                      • ADezii
                        Recognized Expert Expert
                        • Apr 2006
                        • 8834

                        #12
                        Originally posted by MNNovice
                        Okay. I see what you mean. But why no names is being displayed on the main form? Why those two text boxes do not even show up? On record no. 1, it should read as "Suchitra Sen" and "Uttam Kumar" for example. But they remain blank and invisible. Why is that?
                        Because you are referring to the Current Record on the Sub-Form the way I read it. Put the Cursor on a Record with an ID of either 1 or 2 in the Sub-Form.

                        Comment

                        • MNNovice
                          Contributor
                          • Aug 2008
                          • 418

                          #13
                          Originally posted by ADezii
                          Because you are referring to the Current Record on the Sub-Form the way I read it. Put the Cursor on a Record with an ID of either 1 or 2 in the Sub-Form.
                          Okay. It works but not the way I intended. First of all, it displays the iccID and NOT the name associated with it.

                          If I were to put my cursor on an ID - it beats the purpose. I intend to automatically display the names of those actors who play the main roles (icrSort = 1 and 2 or Hero or Heroine) in a given movie.

                          Hope this makes sense. Thanks again for your help. M

                          Comment

                          • NeoPa
                            Recognized Expert Moderator MVP
                            • Oct 2006
                            • 32653

                            #14
                            Subscribing for later :)

                            Comment

                            • ADezii
                              Recognized Expert Expert
                              • Apr 2006
                              • 8834

                              #15
                              Originally posted by MNNovice
                              Okay. It works but not the way I intended. First of all, it displays the iccID and NOT the name associated with it.

                              If I were to put my cursor on an ID - it beats the purpose. I intend to automatically display the names of those actors who play the main roles (icrSort = 1 and 2 or Hero or Heroine) in a given movie.

                              Hope this makes sense. Thanks again for your help. M
                              How about Posting some specific examples from Records contained within the Sub-Form from the Demo DB, listing the specific Main Record Number, Sub-Form Record(s), Hero/Heroine's Name, etc. This is one of those problems that is very hard to conceptualize from the opposite end of a Web Page (LOL).

                              Comment

                              Working...