Consulting

Results 1 to 4 of 4

Thread: Solved: conditions for multiplecomboboxes

  1. #1
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location

    Solved: conditions for multiplecomboboxes

    Good morning,

    Today is a nice day (sunny day). Anyway, what I need to do and I can not:
    I have 15 comboboxes and I like to put an condition like this
    If all comboboxes are empty do the code if not do something else:


    [VBA]
    For i = 1 To 15
    If Me.Controls("ComboBox" & i).Text = "" And Me.Controls("ComboBox" & i + 1).Text = "" etc .... Then
    code 1
    Else
    code 2
    End If
    Next

    [/VBA]

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Not tested, but maybe:
    Dim bolNotEmpty As Boolean
        For i = 1 To 15
            If Not Me.Controls("ComboBox" & i).Text = vbNullString Then
                bolNotEmpty = True
                Exit For
            End If
        Next
        
        If Not bolNotEmpty Then
            'code 1
        Else
            'code 2
        End If

  3. #3
    VBAX Mentor
    Joined
    Dec 2009
    Posts
    416
    Location
    perfect

    thx Mark

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Here's another aproach[VBA] For i = 1 To 15
    If Not Me.Controls("ComboBox" & i).Text = vbNullString Then
    ' code 2
    GoTo Skip
    End If
    Next

    'code1

    Skip:
    'continue[/VBA]

Posting Permissions

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