+ Reply to Thread
Results 1 to 5 of 5

Knowing which button was clicked on UserForm?

  1. #1
    Registered User
    Join Date
    10-27-2006
    Posts
    18

    Knowing which button was clicked on UserForm?

    I have a user form in Excel that is filled at run time with variable number of CommandButtons named after values in spreadsheet.

    So you end up with variable number of buttons named for example "Germany, England, Scotland etc.".

    That works fine via Me.Controls.Add method!

    NOW, I WANT TO KNOW WHICH BUTTON WAS CLICKED. HOW DO I DO THAT?

    Thanks!

  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,258
    Hello Riorin,

    When say "user form" what are you referring to, a worksheet with controls on it or a VBA UserForm? If these controls are on a worksheet, are they Forms toolbar or Control Toolbox controls?

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    10-27-2006
    Posts
    18
    When say "user form" what are you referring to,
    I'm referring to VBA user form.

    Created in Visual Basic Editor by New User Form with all belonging events and properties - I use UserForm_Initialise() to populate the form with dynamic command buttons named after countries currently in a spreadsheet list.

  4. #4
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile

    Good morning Riorin

    Use a class module. In the example attached I have populated the userform at design time, rather than run time as you have for the sake of simplicity, but the same principle applies.

    HTH

    DominicB
    Last edited by dominicb; 08-19-2008 at 04:30 AM.
    Please familiarise yourself with the rules before posting. You can find them here.

  5. #5
    Registered User
    Join Date
    10-27-2006
    Posts
    18
    Thanks dominicb!

    Thanks a ton! Worked like a charm!

    Can't really call it intuitive solution, would have never come up with that on my own!

    It was much simpler in Access VBA where you have something like "Show me the control that triggered the event" in form's OnClick event and voila problem solved!

+ 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