Consulting

Results 1 to 4 of 4

Thread: Multiple Controls on a Form

  1. #1
    VBAX Newbie
    Joined
    Sep 2015
    Posts
    4
    Location

    Multiple Controls on a Form

    I have a matrix of 4 x 3 combo boxes on a form and wish to perform the same action on each of the 12 (ie make visible, set font, set list index get input etc etc etc) Do I have to write routines specific to each control or can I build up commands by stringing the various parts of the box address into a variable and obeying that variable.
    I have tried the latter but it doesn't seem to work (eg com = "t"&t&"c"&c&".visible = false" to hide a control - the content of com looks OK but how do I get Excel to perform it.
    Any ideas or suggestions would be welcome.

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    You should be able to do something along these lines:
    For i = 1 To 12
      Controls("Combobox" & i).BackColor = &H80000002
    Next i
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Newbie
    Joined
    Sep 2015
    Posts
    4
    Location
    Thanks a million - seems to do what I need - easy when you know how and you obviously know how - thanks again

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,729
    Location
    I like to give UF controls a meaningful name instead of Combobox1, etc. i.e cboxJan, cboxFeb, etc.

    If there's different kinds then the .Tag property can provide finer control



    Option Explicit
    
    Private Sub UserForm_Initialize()
        Dim oControl As Control
        
        For Each oControl In Me.Controls
            If TypeOf oControl Is ComboBox And oControl.Tag = "MONTH" Then
                oControl.BackColor = &H80000002
            End If
        Next
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •