+ Reply to Thread
Results 1 to 2 of 2

Referring to UserForm and Control via Variables

  1. #1
    Valued Forum Contributor
    Join Date
    06-02-2012
    Location
    London, England
    MS-Off Ver
    365
    Posts
    397

    Referring to UserForm and Control via Variables

    Hi all. I'm hoping there is an easy solution to this. Perhaps something I'm just overlooking.

    I have a userform with a multipage control. Some of the pages on the multipage are very similar and require some formatting of other controls on the same page to work in the same way.

    For example:

    On page1 when Pg1optionbutton1 is true I need certain controls on the same page to become disabled.
    But if Pg1optionbutton2 is true (forcing Pg1optionbutton1 to false) then I need those controls to be enabled again.

    This process repeats for several of the pages and the code to enable/disable all these controls is quite hefty (there are more scenarios than just this one per page) and to make matters more complicated there are also more than one of these userforms, so I was hoping I could have a sub in a module that would perform all these changes but using variables for userform name and control name.

    Below is code I'm attempting (very much simplified):

    FormName and CtrlName are defined as Public strings in a standard module.

    On userform1:
    Please Login or Register  to view this content.
    Then in a standard module I have:

    Please Login or Register  to view this content.
    However, when I select Pg1OptionButton1 it calls the right sub but fails on the line provided above with a Runtime Error 13 - Type Mismatch.


    Any help on this would be greatly appreciated. Been banging my head on this one for far too many hours now!

    Many thanks.

    B.

    PS. I know a sample workbook would be very helpful but this is part of a much bigger project and pulling it to bits would be almost impossible.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Referring to UserForm and Control via Variables

    Pass each affected control to the global subprocedures like this...

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    ...A more condensed version
    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Excel 2007, Userform Textbox Date Format and Calendar Control Userform
    By riffology in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-03-2014, 06:18 PM
  2. [SOLVED] referring to values in a userform combobox as range
    By Sc0tt1e in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-29-2013, 09:38 AM
  3. Cell contents referring to userform and text box to pass data to
    By wonderdunder in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-02-2013, 08:02 AM
  4. Assigning Variables to Control TextBox and Column
    By bbarrene in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-14-2010, 07:45 PM
  5. Accessing variables assigned in one userform by a second userform?
    By jerseyguy1996 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-30-2009, 04:12 PM
  6. Referring to a userform control
    By MattShoreson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2007, 07:15 AM
  7. referring to objects using string variables?
    By Baapi in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-30-2007, 02:34 PM
  8. [SOLVED] UserForm referring to another excel file
    By B Smith in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2005, 03:30 AM

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