Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

checking the text value in combo box 1

Status
Not open for further replies.

krzysrb

Technical User
Jun 23, 2003
30
CA
Hey all

I am wondering if any of you is aware if there is a way to check and see if the text value of a combobox is in the list of the values for that given combobox.

I had this code running and it doesnt seem to work very well. Even if I have the right name of the day, it still says it is not the same. I would like this to end the FOR loop as soon as it finds out whether the input in the combobox is in the preset values or not, so I can move on with the program.

For i = 0 to cboDay.ListCount
If UCase(cboDay.Text) <> UCase(cboDay.List(i)) Then
MsgBox &quot;Not same&quot;
Exit Sub
End If
Next i

thanks a lot
vlada
 

If you dont want the user to type, set the ComboBox Style property to 3-Dropdown List or use these to programmatically do it.

Two Steps.
1. Write KeyCode = 0 in the cmbName_KeyDown Event
and
2 Write KeyAscii = 0 in the cmbName_KeyPress Event
 
When your code compares the the text in the combo box with the first item in the list box and it is not the same it will give you the message - you are not looping through the whole list box.

Try this . . .

Dim bNotTheSame as Boolean

For i = 0 to cboDay.ListCount
If UCase(cboDay.Text) = UCase(cboDay.List(i)) Then
bNotTheSame = True
End If
Next i


If Not bThesame Then
MsgBox &quot;Not same&quot;
Exit Sub
End If


Does this solve your problem? Or am I missing something?
[elephant2]

The pen is mightier than the sword - and quite frankly . . easier to write with
 

tb, you solved it right man. Thanks a lot. I have been thinking of triggering the flag in case of incorrect entry, but i couldnt never get it how to use it.

thanks again man
vlada
 
Thnx 4 my star !!


PS.
>man

I am allowed to wear pink !!!

[lol]

The pen is mightier than the sword - and quite frankly . . easier to write with
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top