none
How to disable ComboBox when CheckBox is False? And how to populate ComboBoxes? RRS feed

  • Question

  • I know it is very simple, but I am having a hard time populating ComboBoxes. In addition, I need to have the comboboxes disabled when checkboxes are unchecked, but enable comboboxes when checkboxes are checked (true). How do I do that? This is what I have so far...

    Thank you!!!

    Private Sub SDForm_Initialize()
       
       With Me.CSComboBox
       .AddItem "Associate Director of Career Services"
       .AddItem "Director of Career Services"
       .AddItem "Student Career Coordinator"
       End With
       
       With Me.RLComboBox
       .AddItem "Assistant Director of Res. Life Admin"
       .AddItem "Admin Asst Residence Life"
       .AddItem "Director of Residence Life"
       .AddItem "Residence Life Coordinator"
       End With
                
    Me.CSCheckBox.Value = False
    If Me.CSCheckBox.Value = False Then
    Me.CSComboBox.Enabled = False
    End If
    If Me.CSCheckBox.Value = True Then
    Me.CSComboBox.Enabled = True
    End If
    Me.RLCheckBox.Value = False
    If Me.RLCheckBox.Value = False Then
    Me.RLComboBox.Enabled = False
    End If
    If Me.RLCheckBox.Value = True Then

    Me.RLComboBox.Enabled = True

    End If

    End Sub
    Thursday, October 3, 2013 1:13 PM

All replies

  • I know it is very simple, but I am having a hard time populating ComboBoxes. In addition, I need to have the comboboxes disabled when checkboxes are unchecked, but enable comboboxes when checkboxes are checked (true). How do I do that? This is what I have so far...

    Thank you!!!

    Private Sub SDForm_Initialize()
       
       With Me.CSComboBox
       .AddItem "Associate Director of Career Services"
       .AddItem "Director of Career Services"
       .AddItem "Student Career Coordinator"
       End With
       
       With Me.RLComboBox
       .AddItem "Assistant Director of Res. Life Admin"
       .AddItem "Admin Asst Residence Life"
       .AddItem "Director of Residence Life"
       .AddItem "Residence Life Coordinator"
       End With
                
    Me.CSCheckBox.Value = False
    If Me.CSCheckBox.Value = False Then
    Me.CSComboBox.Enabled = False
    End If
    If Me.CSCheckBox.Value = True Then
    Me.CSComboBox.Enabled = True
    End If
    Me.RLCheckBox.Value = False
    If Me.RLCheckBox.Value = False Then
    Me.RLComboBox.Enabled = False
    End If
    If Me.RLCheckBox.Value = True Then

    Me.RLComboBox.Enabled = True

    End If

    End Sub

    You will need to write an event macro when the checkbox is clicked. Just double-click on checkbox in VBA editor, you will get something like the following. By the way for Booleans, there is no need to use = True or = False, just use "If myBool" or "If Nor myBool"

    Private Sub CheckBox1_Click()
         'Insert code here If Checkbox1.Value Then ...
    End Sub

    Thursday, October 3, 2013 3:55 PM