Results 1 to 5 of 5
  1. #1
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Send controls form to macro (ALL except 2007)

    I have a custom pop up menu assigned to a specific control on a sub form.
    I need to send the macro (which uses RunCode) the name of the subform (not the control name),
    because it needs to pick up additional data.
    The macro then calls a function that does the data processing.
    However, in the Function, the form name returned is from the parent form of the subform,NOT the subform itself.
    I need to determine which because there are 3 diffent subforms on the same main form that need to make use of the same routine.
    How can I pass the name of the subform to the macro.

    I have found a possible option, but I have to use

    screen.activecontrol.parent.name instead of passing an argument.

    The argument method is the preferred solution (if possible).

    many thanks
    Andrew

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

    Re: Send controls form to macro (ALL except 2007)

    What's wrong with the method you found? I'd stick with it.

  3. #3
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Send controls form to macro (ALL except 2007)

    I can live with the method I've found as long as it is consistent across all versions (someting I have not tested yet).

    However, I was wondering why when the call menu is referenced from the control on the subform, why it still send the parent form. Maybe it is because the subform is not open in its own right, only as part of the main form.
    However, from a true object point of view, it would have made more sense for it to send the subform.

    That aside I'll have to live with it unless there is an alternative.

    Just as a matter of interest, is there a way to send the active control from a macro to a function.
    For a form you can use the syntax FunctionName(Form).

    I can also use the syntax Functionname([NamedControl])

    What is the Equivalent of passing the active control to a function,
    because this would also be useful, rather than always needing to go via the screen object in vba.
    Andrew

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

    Re: Send controls form to macro (ALL except 2007)

    You can use

    FunctionName([Screen].[ActiveControl])

    if you want to pass the active control as argument, or

    FunctionName([Screen].[ActiveControl].[Parent])

    if you want to pass the form containing the active control (which may be a subform) as argument.

  5. #5
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Send controls form to macro (ALL except 2007)

    Thanks.

    I should have thought of that, since I was using it in my code anyway.
    Andrew

Posting Permissions

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