Copy from a subform to a text field in the main form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Juan Plaza
    New Member
    • Jun 2011
    • 5

    Copy from a subform to a text field in the main form

    I set up an unbound subform on a main form. I need the user to be able to choose items from the sub-form and have them populate in a bound text field in the main form in paragraph style.

    The sub-form is kind of like a template the user uses to document in paragraph form.

    I am a bit of a novice. I would appreciate any help.
    Thank You

    Juan
  • jpatchak
    New Member
    • Oct 2006
    • 76

    #2
    You can just throw this code into your sub form's "On Current" event:
    Code:
    Forms!mainFormName.Form.mainTextBox.Value = Me.TextBoxNameFromSubform.Value

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32636

      #3
      See Referring to Items on a Sub-Form for more ways to refernce controls on your subform.

      Comment

      • Juan Plaza
        New Member
        • Jun 2011
        • 5

        #4
        Jpatchak, thank you for your insight. I crossed the first hurdle which was getting the subform options recorded in the bound text box of the main form. The problem I have now is that it only records a single option. If the user picks a second option it replaces what it had recorded previously. I need it to record all the options the user picks in the text box.

        Thank You

        Juan

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32636

          #5
          You ask for help putting the data together, yet you don't give any indication of what that data together should look like.

          A solution might be the following :
          Code:
          Forms!mainFormName!mainTextBox = IIf(IsNull(Forms!mainFormName!mainTextBox), _
                                               "", _
                                               Forms!mainFormName!mainTextBox & ",") & _
                                           Me.TextBoxNameFromSubform
          But frankly it's hard to know unless you make a bit more effort expressing the problem properly before posting.

          Comment

          • Juan Plaza
            New Member
            • Jun 2011
            • 5

            #6
            NeoPa, I am sorry if I was vague. I am just try get the user to make a paragraph in a bound field of a main form from template choices in a subform.

            In the click event on the unbound subform,I included:
            Code:
            variable=nz(Forms![mainform].form.bound field.value)
            Forms![main form].form.bound field.value= variable & chr(13) & Me![selected field in the subform].value & "."
            Thank You

            Juan
            Last edited by NeoPa; Jun 20 '11, 10:36 PM. Reason: Added mandatory CODE tags

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32636

              #7
              I'm struggling to match this with what you requested, but a simpler form of this might be :
              Code:
              With Forms![mainform].form.[bound field]
                  .Value = .Value & vbNewLine & Me.ActiveControl & "."
              End With
              I'm still guessing to a certain extent, but you might want to try it if this is what you're after.

              Comment

              • Juan Plaza
                New Member
                • Jun 2011
                • 5

                #8
                NeoPa, thank you for your response. I will try it. I'll let you know how it goes.

                Juan

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32636

                  #9
                  You're welcome. It's been a pleasure dealing with you Juan :-)

                  Comment

                  • Juan Plaza
                    New Member
                    • Jun 2011
                    • 5

                    #10
                    I am trying get everything to populate in the bound field in paragraph form. Your code works perfect except for the vbNewLine. I erased it and it gave me exactly what I was looking for.

                    Thank You

                    Juan

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32636

                      #11
                      My vbNewLine was simply a replacement for your Chr(13) Juan. If it works better without it then that's all good :-)

                      I suspect (but not sure as I don't play there much) that a bound Memo type field would display that OK, but not a Text type one. As I say though, I'm not sure.

                      Comment

                      Working...