Results 1 to 8 of 8

Looping through object names

Threaded View

pdauction Looping through object names 09-21-2011, 10:52 AM
Leith Ross Re: Looping through object... 09-21-2011, 12:46 PM
pdauction Re: Looping through object... 09-22-2011, 04:12 AM
snb Re: Looping through object... 09-22-2011, 04:23 AM
Andy Pope Re: Looping through object... 09-22-2011, 04:25 AM
Kyle123 Re: Looping through object... 09-22-2011, 04:31 AM
pdauction Re: Looping through object... 09-22-2011, 04:45 AM
e4excel Re: Looping through object... 09-22-2011, 05:01 AM
  1. #1
    Registered User
    Join Date
    09-07-2009
    Location
    Lytham, England
    MS-Off Ver
    Excel 2003+07
    Posts
    75

    Looping through object names

    Hi, I have the following code where I have a lot of objects (labels and combo boxes) on a userform which I want to make enable/disabled. My intial code is supposed to make them all diasbled... Here is the long way of doing it...
    frmUW.lblnewlife.Enabled = False
    frmUW.cbonewlife.Enabled = False
    frmUW.lblnewlici.Enabled = False
    frmUW.cbonewlici.Enabled = False
    frmUW.lblnewci.Enabled = False
    frmUW.cbonewci.Enabled = False
    frmUW.lblnewip.Enabled = False
    frmUW.cbonewip.Enabled = False
    frmUW.lblnewtpd.Enabled = False
    frmUW.cbonewtpd.Enabled = False
    frmUW.lblnewwop.Enabled = False
    frmUW.cbonewwop.Enabled = False

    To help me with the further coding I have tried to do this as a loop but am struggling. Here is my broken code...
    Dim ben As Object
    Dim benefit As String
    'Disable all lbl's and cbo's initially
    'U/W Decision
    x = 0
    
    Do Until x = 6
    
    Select Case x
        Case 0
            Set ben = frmUW.lblnewlife
            benefit = "life"
        Case 1
            Set ben = frmUW.lblnewlici
        Case 2
            Set ben = frmUW.lblnewci
        Case 3
            Set ben = frmUW.lblnewip
        Case 4
            Set ben = frmUW.lblnewtpd
        Case 5
            Set ben = frmUW.lblnewwop
    End Select
    
    ben.Enabled = False
    frmUW.lblnew" & benefit &".Enabled = False
    frmUW.cbonew" & benefit &".Enabled = False
    
    x = x + 1
    
    Loop


    As you can see I have 2 solutions within the same code I was testing
    The ben variable stuff does seem to work but it is the benefit stuff I would really like to work. Is this kind of thing possible? i.e. frmUW.lblnew" & benefit &".Enabled = False

    Many Thanks
    Last edited by pdauction; 09-22-2011 at 04:46 AM. Reason: Added Code Tags

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