none
Form name as parameter? RRS feed

  • Question

  • Hi all-

    Is it possible to pass a form name as a variable/parameter?

    In other words, let's say I have Forms A, B, C, and D.

    Currently, I access Form D by click a button on Form A.

    Form D has a text box the contents of which populate a related text box on Form A (by using a specific reference in it's code to Form A).

    What I'd like to do is pass to Form D the name of the form accessing it, and then have that form be the one that receives the text from the textbox on Form D.

    Tuesday, October 13, 2015 5:26 PM

Answers

  • What I'd like to do is pass to Form D the name of the form accessing it, and then have that form be the one that receives the text from the textbox on Form D.

    Hi Casey_M,

    One way to handle these things is to pass the formname of the calling form to the called form using the OpenArgs argument. The DB guy mentioned that already.

    Inside the Open event of the called form you can make a reference to the calling form using:

        prev_formname = Me.Openargs (or use some function to extract the formname from OpenArgs, if OpenArgs represents more information)
        Set prev_form = Forms(prev_formname).

    From then on you can reference any control on the prev_form using   prev_form!MyControl, in the same way as you reference controls on the current (called) form using   Me!MyControl.

    Imb.

    • Marked as answer by Casey_M Wednesday, October 14, 2015 2:05 AM
    Tuesday, October 13, 2015 9:40 PM

All replies

  • Yes. One way to do it is  by using a custom function.

    • Edited by .theDBguy Tuesday, October 13, 2015 5:47 PM
    Tuesday, October 13, 2015 5:45 PM
  • Forms![Form A]![Control Name]=Forms![Form D]![Control Name]

    or

    Me.Control Name=Forms![Form D]![Control Name]

    Tuesday, October 13, 2015 5:55 PM
  • How would this work?
    Tuesday, October 13, 2015 6:15 PM
  • How would this work?
    I guess you could pass the name of the calling form through the OpenArgs parameter and then use it with that syntax.
    Tuesday, October 13, 2015 6:25 PM
  • What I'd like to do is pass to Form D the name of the form accessing it, and then have that form be the one that receives the text from the textbox on Form D.

    Hi Casey_M,

    One way to handle these things is to pass the formname of the calling form to the called form using the OpenArgs argument. The DB guy mentioned that already.

    Inside the Open event of the called form you can make a reference to the calling form using:

        prev_formname = Me.Openargs (or use some function to extract the formname from OpenArgs, if OpenArgs represents more information)
        Set prev_form = Forms(prev_formname).

    From then on you can reference any control on the prev_form using   prev_form!MyControl, in the same way as you reference controls on the current (called) form using   Me!MyControl.

    Imb.

    • Marked as answer by Casey_M Wednesday, October 14, 2015 2:05 AM
    Tuesday, October 13, 2015 9:40 PM