Reputation: 95
I have 6 comboboxes on one form - they are in an array. They are called cboClient(0) thru cboClient(5). What I'm trying to do here is validate that there is a value so something along the lines of
if cboclient(0)<>"" and not isnull(cboClient(0)) then
'Do this
End if
Each cbo gets populated with the same list of items. My goal is to make sure that user CAN'T make the same selection in more than 1 cbo. Basically if they choose item 1 in cboClient(0), that item cannot be selected in any other cbo.
I'm trying to find a way so that I can do this in as few lines as possible, I could potentially do it like this..but it would be extremely long as I have to verify each cbo against the others
if cboClient(0).text <> cboClient(1).text then
msgbox "OK"
Else
msgbox "Please choose again"
End if
I'm trying to somehow write it possibly in a loop? to verify the .text in each cbo and make sure no two identical selection were made. Any idea?
EDIT: I have 6 cbo's - each one gets populated with the same data (say data numbers 1 through 10). If user selects "1" in cboClient(0), they can't select this in another cbo. I don't necessarily want to hide it from them - but once they click SAVE - I want to have a function in place to run through the CBO's and check if they've selected the same item more than once - if they have, I want to give them a MsgBox saying "Fix your selection, you cannot have two items"
EDIT 2:
Maybe do two loops - one within another...
dim a as integer
dim b as integer
for a = 0 to 5
for b = 1 to 5
if cboClient(a).text <> cboclient(b).text then
'keep going
else
MsgBox "you have made the same selection"
End if
next b
next a
Something like that?
Upvotes: 0
Views: 172
Reputation: 3745
Try this code :
For i = 0 To 5
For j = 0 To 5
If i <> j And cboClient(i).Text = cboClient(j).Text Then
MsgBox "You must choose diffirent values, Please choose again"
Exit Sub
End If
Next
Next
Upvotes: 1