+ Reply to Thread
Results 1 to 4 of 4

Passing parameters to class modules

  1. #1
    Registered User
    Join Date
    07-09-2010
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    26

    Passing parameters to class modules

    Hello,
    Leith Ross showed me the other day a way of identifying the UserForm control in focus through the function:
    Please Login or Register  to view this content.
    I’d like to take a step further and pass parameters to a class module and depending on which control (CommandButton) is pressed, take a different action.

    I have in the Initialize section of the multipage UserForm:
    Please Login or Register  to view this content.
    and in the NavBtnClass class module

    Please Login or Register  to view this content.
    Is it possible to pass a parameter to the class module changing the Multipage1.Value?

    If I put a value in the Button Tag property I can use f.i. myTag=Right(Ctrl.Tag,1) to extract
    the MultiPage number I want this particular Button to direct me to, but I don’t know how to pass this parameter to the class module!

    Regards
    Mats
    Last edited by Mats Samson; 10-25-2011 at 06:03 PM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Passing parameters to class modules

    Hello Mats,

    The attached workbook is an example of adding custom properties to a Class object. In this example, I have added two: Name and MenuPage. The Name property allows you to assign a unique name to the SubClassed control. The MenuPage is a variant so you can use either a number or string to represent the menu page of the control. If you need help adapting the code, let me know.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    07-09-2010
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Passing parameters to class modules

    Thanks Leith,
    I will check your proposal.....tomorrow It's almost midnight!!!
    I found even a very simple solution myself!
    Adding a Tag parameter I could use "GetActiveControl.Tag" to read the specific parameter for the specific Button. After adding the parameter to a variable and changing the MultiPage1.Value = myVar it jumped to the desired page! Thanks any way!

  4. #4
    Registered User
    Join Date
    07-09-2010
    Location
    Helsingborg, Sweden
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Passing parameters to class modules

    Leith, I checked your proposal and it's a veeery elegant solution and opens a lot of possibilities
    to merge controls with similar tasks to a few procedures instead of having one for each control.
    Thanks again!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1