Error testing combobox to variable
Hi
The code below should work for you it uses pretty much the same idea
as your code only using a single loop rather than nesting another loop
inside the initial loop. I personally find it easier to keep loops
simple as the more complex they get and the more nesting is used it
becomes hard to know where you are while you are debugging your code.
The main problem with you loops are that the first loop will run for
ever as cnt will always be 3 due to the fact it is incremented in the
inner loop this is what makes it seem as excel has locked up, it is
actually running the loop endlessly you can stop the loop from running
by using the Ctrl + Break keystroke to break the running code.
Also worth a mention is that without an exit of the loops after the
correct name is found the inner loop will continue to check the rest
of the combobox contents which is unnecessary.
i = False
NewName = TxtFirstName & "," & TxtLastName
cnt = 0
Do While i = False And cnt <= CboNames.ListCount - 1
If CboNames.List(cnt) = NewName Then
MsgBox NewName & " Is already on the list"
i = True
Else
cnt = cnt + 1
End If
Loop
Steve
|