Reputation: 1203
I want to check the value in a dropdown list. The list is preconfigured to hold a yes or a no.
At the moment, I am using a check box, that looks like this:
If chkboxOne.Value = vbChecked And (LenB(txtDetailsRefNo.Text) = 0) Then
If vblnShowErrors Then Err.Raise 10000, VALIDATION, "A Default Reference Number must be entered."
blnDataFail = True
End If
Can I simply change chkboxOne to "cboboxOne" by swapping the checkbox for a combobox on the form, and replacing "vbChecked" with True? I'm not sure how similar their functionality is syntax wise.
Thanks
Upvotes: 2
Views: 273
Reputation: 175768
To get the item in a combobox you can examine the listindex
to see whats selected (there is no value
property)
cboboxOne.AddItem "yes" '//listindex is 0
cboboxOne.AddItem "no" '//listindex is 1
cboboxOne.AddItem "maybe" '//listindex is 2
...
if (cboboxOne.ListIndex = 0) Then '// yes selected
You can also examine the selected text:
if (cboboxOne.List(cboboxOne.ListIndex) = "yes") Then '// yes selected
You can also test against custom integers using ItemData
cboboxOne.AddItem "yes"
cboboxOne.ItemData(cboboxOne.NewIndex) = 42
cboboxOne.AddItem "no"
cboboxOne.ItemData(cboboxOne.NewIndex) = &HBEEF
...
if (cboboxOne.ItemData(cboboxOne.ListIndex) = 42) Then '// yes selected
Upvotes: 3