Results 1 to 10 of 10
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Referencing Text Boxes Amongst Subforms (2000)

    How can I reference a subform text box from a text box on another subform when both are contained by the same form? I've tried to do so in the PORT1 text box on the MG2Dez subform of the attached mdb but I get a #Name? error.

    Here's the content of the control source for the PORT1 text box on the MG2Dez subform:
    =[Pmedia]*[Forms]![dezzo]![QT]/([pmedia]+<font color=red>[Forms]![mg3dez]![pmedia]</font color=red>)
    the part in <font color=red>red</font color=red> is not recognized.
    Attached Files Attached Files

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Referencing Text Boxes Amongst Subforms (2000)

    A subform is not part of the Forms collection, only main forms are. You can use this:

    Parent![Gruppo 3 Dezzo]!pmedia

    or

    Forms![dezzo]![Gruppo 3 Dezzo]!pmedia

    By the way, note that I use the name of the subform as a control on the main form here, not the name of the subform in the database window.

  3. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Referencing Text Boxes Amongst Subforms (2000)

    Thank you Hans, I've carried out your advice(please see attached mdb) but now when I open the file I get the attached error message.
    Attached Files Attached Files

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Referencing Text Boxes Amongst Subforms (2000)

    You must have changed something else too, for I didn't get that error in the database you posted earlier.

  5. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Referencing Text Boxes Amongst Subforms (2000)

    Believe me I just modified the Control Source for the PORT1 text box into
    =[PMedia]*[Forms]![dezzo]![QT]/([PMedia]+[Forms]![dezzo]![Gruppo 3 Dezzo]!pmedia)
    Can you post the database with your modification?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Referencing Text Boxes Amongst Subforms (2000)

    Here it is. It does not exhibit the error message you got, but it still doesn't work correctly if you select some dates. There is some kind of circular calculation going on, but it's far too complicated for me to understand.
    Attached Files Attached Files

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Referencing Text Boxes Amongst Subforms (2000)

    Can the same syntax(Parent![Gruppo 3 Dezzo]!pmedia) work when you have your subforms inside a Tab Control on the main form?
    Please check the PORT1 text boxes in the subforms inserted in the Page2 and Page3 pages of the Tab Control in the attached mdb. I've tried that but I get the #Name? error.
    Attached Files Attached Files

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Referencing Text Boxes Amongst Subforms (2000)

    Giorgio,

    You should insert error handling in the functions in Module1, as I indicated in <post#=375765>post 375765</post#>. This will prevent the error messages you get when one of the arguments to a function is undefined.

    And you should use the name of the subforms as controls on the main form. In this version, they are named MG1Dez, MG2Dez and MG3Dez, not Gruppo 1 Dezzo etc. For example, the Control Source of PORT1 in the subform on Page2 should be

    <code>=qx([PMedia],Forms!dezzo!txtQT,Parent!MG2Dez!pmedia)</code>

    or

    <code>=qx([PMedia],Parent!txtQT,Parent!MG2Dez!pmedia)</code>

  9. #9
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Referencing Text Boxes Amongst Subforms (2000)

    Thank you Hans, works perfectly.
    Now, since the PORT1, REND and COEFF text boxes in both the MG1Dez and MG2Dez don't update right away when I, e.g., select Jan 1, 2004 on the calendar and change the values in the txtQt and SALTO text boxes on the main form, I thought I could solve the problem by putting code in the AfterUpdate event of the txtQt and SALTO text boxes that would call the functions set as control sources for the PORT1, REND and COEFF text boxes:

    Private Sub salto_AfterUpdate()
    Forms!MG2Dez!Rend = Rendi([Energia], [PORT1], [PMedia], [Forms]![dezzo]![Salto])
    Forms!MG3Dez!Rend = Rendi([Energia], [PORT1], [PMedia], [Forms]![dezzo]![Salto])
    Forms!MG2Dez!Coeff = CEner([Energia], [PORT1], [Rend], [Forms]![dezzo]![Salto])
    Forms!MG3Dez!Coeff = CEner([Energia], [PORT1], [Rend], [Forms]![dezzo]![Salto])
    End Sub

    Private Sub txtQt_AfterUpdate()
    Forms!MG2Dez!PORT1 = Qx([PMedia], [Forms]![dezzo]![txtQt], Forms!MG3Dez!PMedia)
    Forms!MG3Dez!PORT1 = Qx([PMedia], [Forms]![dezzo]![txtQt], Forms!MG2Dez!PMedia)
    End Sub

    but I get an error message when I try to change values in either the txtQt or SALTO text boxes.
    Attached Files Attached Files

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Referencing Text Boxes Amongst Subforms (2000)

    I think you should reconsider the design of this form and its subforms. It has become far too complicated, and as I remarked earlier, there are circular references that make the whole setup unstable. Your code has the following problems, but trying to solve them only seems to make it worse. The following are only remarks, they don't make the thing work.

    1. A subform is not part of the Forms collection (haven't we been there before?), so <code>Forms!MG2Dez</code> is not valid. You must use <code>Forms!Dezzo!MG2Dez</code>.
    2. The code you posted here runs from the main form Dezzo. Energia, PORT1 etc. are not controls or fields of Dezzo, so they are unknown to the code. You must use <code>Forms!Dezzo!MG2Dez!Energia</code> etc.
    3. For the same reason, you don't need to use <code>[Forms]![dezzo]![Salto]</code> here, <code>Me.Salto</code> is sufficient.
    4. If you set the value of Rend and Coeff in code, you must clear their Control Source. You can't set the value of a calculated control.

Posting Permissions

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