0
votes

I have a combo-box that accepts multiple values. It is set up like this:

[] Empty
[] Math
[] Science
[] English

A user can select multiple options. However, when a user selects Empty, then the value should be blank or an empty string. The current implementation allows for the value to be a combination of 'Empty' and an actual subject.

I am using the AfterUpdate() event here

Private Sub Classes_Value_AfterUpdate()
Dim counter As Integer
For counter = 0 To MyComboBox.ItemsSelected.Count - 1
  If MyComboBox.ListIndex(counter) = "Empty" Then
    Me.MyComboBox.Value = " " 
End Sub

But it doesn't seem to like the .ListIndex(counter) line. I can't seem to check the value appropriately in my loop.

1
A user cannot select multiple values in a combo box. Perhaps you mean listbox ? - ashleedawg
My combo-box has the option to check multiple values. Once I hit 'Ok' then the value will be the concatenation of all the checked boxes. - user9710116
It sounds more like a Checkbox Dropdown List as opposed to Combobox? - ashleedawg
Yeah, that's more accurate, actually. Let me edit - do you think its solvable? - user9710116
Of course, its a new feature of Access. I haven't used them personally but before I Google it, are you saying you're returned a comma separate string of values that you need to parse each value? ie, yourString="Blue,Green,Red" (or that the .Value of the control is Blue,Green,Red)? If so, I have a solution. - ashleedawg

1 Answers

0
votes

You can use the .Value property of the multi-valued combo box. That's an array of all selected values.

Private Sub Classes_Value_AfterUpdate()
    Dim v As Variant
    For Each v To MyComboBox.Value
      If v = "Empty" Then
        Me.MyComboBox.Value = Null
        Exit Sub
      End If
    Next
End Sub

You can use this, but from an UX view, I highly recommend you don't use it and add a Clear button instead to set the field to Null.