+ Reply to Thread
Results 1 to 8 of 8

Looping through buttons in Userform

  1. #1
    Registered User
    Join Date
    05-26-2007
    Posts
    7

    Looping through buttons in Userform

    Hello! Having a little trouble with this :chuckle:

    I need for my macro to loop through all the buttons in a userform in order to read the caption on each one and look for appropriate instructions to perform calculations. The calculations themselves are easy and I can manage to code them.

    However, it's the loop that I'm havin trouble with, as I have no idea on how to declare it.

    Please Login or Register  to view this content.
    Thanks in advance for your help!

  2. #2
    Forum Contributor
    Join Date
    07-01-2008
    Location
    Cincinnati, OH
    Posts
    150
    Quick and easy...

    Please Login or Register  to view this content.

  3. #3
    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 afternoon estacio

    I personally would use a class module for this type of task, but in terms of looping through controls a quick and dirty example would be :

    Please Login or Register  to view this content.
    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Not sure why you are using the button's caption like this but

    Please Login or Register  to view this content.
    Last edited by royUK; 09-01-2008 at 10:37 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  5. #5
    Registered User
    Join Date
    05-26-2007
    Posts
    7
    Thank you very much, that's exactly what I needed.

    Regarding why I'm using the captions, it's fairly simple. It's because of the system I use to keep myself organized. I tend to name arrays "aName", integers for iterations "iName", forms "frmName", Buttons "btnName" and so on.

    The captions on the buttons, however, happen to have a direct correspondence to a database I have, so it's easy to reference.

  6. #6
    Registered User
    Join Date
    05-26-2007
    Posts
    7
    There appears to be a problem.

    when using:
    Please Login or Register  to view this content.
    CommandButton appears written in all-lowercase and I cannot access the properties of a commandbutton (caption and backcolor being the ones I need the most).

    However, I tested with another class and by making CmdBtn a ComboBox, for instance, I can use all the properties of a ComboBox. This is only happening for CommandButtons.


    Using
    Please Login or Register  to view this content.
    is not working because .Caption and .BackColor are not properties of the .Control class.

    What's going on? I'm pretty sure I got all the correct libraries referenced. I even see the dropdown box then I type MSForms and CommandButton is listed.

  7. #7
    Forum Contributor
    Join Date
    07-01-2008
    Location
    Cincinnati, OH
    Posts
    150
    If...
    Dim CmdBtn as MSForms.Control
    ...then access the underlying object like...

    CmdBtn.Object.Property
    CmdBtn.Object.Method

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Here's some alternative methods


    Please Login or Register  to view this content.

+ 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. Execute code from auto generated buttons in a userform
    By Tellus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-27-2008, 09:07 AM
  2. Why Userform Buttons Don't Match System Buttons?
    By msleger in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2008, 12:43 PM
  3. userform with frame and option buttons
    By erich_7719 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-25-2008, 11:57 AM
  4. Userform buttons not working on dynamic form
    By Fazered in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-29-2007, 12:16 PM
  5. Userform Radio Buttons
    By neodjandre in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-19-2007, 09:49 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