none
MS Access 2010- Control value sharing across forms RRS feed

  • Question

  • Hi

    in MSaccess world how do we share/pass/accessing value from a textbox in subform to a parent form and vice a versa.

    My current code(below) placed in parent form... but this throws error saying cannot find ctrl...

    Me!Form_XYZSubForm!ControlName_FirstName 

    Thanks

    S


    • Edited by StSingh Wednesday, August 21, 2019 10:27 AM
    Wednesday, August 21, 2019 10:16 AM

Answers

  • The syntax to reference a control in a subform in the ControlSource property of a control in the parent form is:

        =[NameOfSubformControl].[Form].[NameOfControlInSubform

    NameOfSubformControl is the name of the control in the parent form's Controls collection which houses the subform.

    To reference a control in a parent form in the ControlSource property of a control in a subform the syntax is:

       =[Parent].[NameOfControlInParentForm]

    You can also use the same syntax when referencing a control in code in the parent form or subform's module of course.


    Ken Sheridan, Stafford, England

    • Marked as answer by StSingh Wednesday, August 21, 2019 10:51 AM
    Wednesday, August 21, 2019 10:37 AM

All replies

  • The syntax to reference a control in a subform in the ControlSource property of a control in the parent form is:

        =[NameOfSubformControl].[Form].[NameOfControlInSubform

    NameOfSubformControl is the name of the control in the parent form's Controls collection which houses the subform.

    To reference a control in a parent form in the ControlSource property of a control in a subform the syntax is:

       =[Parent].[NameOfControlInParentForm]

    You can also use the same syntax when referencing a control in code in the parent form or subform's module of course.


    Ken Sheridan, Stafford, England

    • Marked as answer by StSingh Wednesday, August 21, 2019 10:51 AM
    Wednesday, August 21, 2019 10:37 AM
  • Personally i find the whole reference issue just a case where "habit" has killed the easiness.

    To refer to any form/report the fundamental requirement is to have it registered as "Microsoft Office Access Class Objects"...and this far easier than you think ...your form/report might even already being registered..as long as it has "code behind"

    The procedure if you are not familar with "code behind" is just open your form/report in design view and hit the button that leads to VBE (Visual Basic Editor)...aka the button "View Code"...and that's about all...nothing more nothing less...if you have already some code it was already registered..but if not just enter the VBE and close it...you don't need even a single line of code.

    After that its just smooth sailing

    Just refer to everything like this :

    Form_Name_Your_Form_OrReport.[Whatever Method/Control you need....with full Intellisense support]

    For example ...if i have a form named Suppliers and i want to Filter it

    Form_Suppliers.Filter = "SupplierID =" & Me.ID

    Form_Suppliers.FilterOn =True

    No more bangs/dot and trying to figure out how to "reach" the Control/Method in question...(it might be easy for 1 Level Nest ...you just copy/paste it from another application...but when it comes to 2nd level or deeper you start writing a long)

    And the bonus of Intellisense is great...you want to refer to a control...e.g a Combobox to Add an Item...if somehow it was a textbox and you thought you should change it to a combobox but forgot it..the Intellisense when it will popup it would simply missing the ".AddItem"...so (?)...you recheck your form...and oops you forgot to "Change" it

    Thursday, August 22, 2019 7:22 AM