+ Reply to Thread
Results 1 to 4 of 4

Passing dynamic useform name

  1. #1
    Registered User
    Join Date
    11-09-2012
    Location
    Earth
    MS-Off Ver
    Excel 2003
    Posts
    7

    Passing dynamic useform name

    Hi guys,

    I've a program which creates a list of employee names and deposits this in a variety of forms as they're activated. I don't want to create duplicate code by stating a fixed name in the code, but would rather pass the required userform name to the sub and off it goes...

    Currently I click on the 'Generate UserForm button' which then runs the below code

    Please Login or Register  to view this content.
    The mdl05_Forms.BuildArrayOfEmployees is another procedure which does the actual list creation and depositing of data into the userform combobox, as below.

    Please Login or Register  to view this content.
    I'm getting a mismatch on the Set UserFormName in the first procedure. I've tried all sorts of combinations of setting variables as Objects, Userforms and Strings, not setting the UserFormName, etc, and I just can't seem to get the UserFormName to pass to the BuildArray procedure.

    I can't quite see where I'm going wrong -- would appreciate any pointers please.

    Cheers, Paul

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Passing dynamic useform name

    Looks like you're really using that as a string, not an object.
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    11-09-2012
    Location
    Earth
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Passing dynamic useform name

    I've tried setting all the variables as a String, and while it does pass the string to the second procedure when it gets to the Userforms.Add(Form).Controls bit it just doesn't do the action. Perhaps that line is just written wrong, somehow. I know the additem does work as it works when I put the hard coded version in (fmShiftChanges.cmbShiftChangeEmployee.additem) it creates the list and puts it into the combobox.

    Ta, Paul

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

    Re: Passing dynamic useform name

    Hello dweben,

    You can get the most recently created UserForm from the VBA USerFoms Collection.
    Please Login or Register  to view this content.
    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!)

+ 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