VB 6 combo box problem

I have a combo box, let called it ZipCode
So, you have to select the appropriate zip code selecting from the combo box
Right now you can just type in the field   instead of selecting.
How to prevent the user from typing anything in the combo box and make sure that the only way to select the value is to select from the combo box
rfedorovAsked:
Who is Participating?
 
Brook BraswellConnect With a Mentor Application Development ManagerCommented:
Make the Combo Box a style of 2 - DropDown List
0
 
Taki EliasConnect With a Mentor Software EngineerCommented:
Check The Properties Of Combo box Style > Select ? Drop Down list
0
 
ZhaolaiConnect With a Mentor Commented:
This is what you need to set in visual mode:
ScreenShot.png
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
rfedorovAuthor Commented:
Thank you, but anybody knows how to validate through the code?
I need my style=0
0
 
ZhaolaiCommented:
What do you mean by "validate through the code"?
Combo1.Style = 0
0
 
rfedorovAuthor Commented:
no, like something preventing the user type in, using let say If statements...
0
 
ZhaolaiCommented:
You said: >How to prevent the user from typing anything in the combo box and make sure that the only way to select the value is to select from the combo box<

But to set the style to 0, you allow user to type into the combo box. Is this what you want?
0
 
rfedorovAuthor Commented:
I know that...
but for what ever reason i am getting the error, when i am changing the style =2...
0
 
ZhaolaiCommented:
Try this:
Private Sub Combo1_KeyPress(KeyAscii As Integer)
    KeyAscii = 0
End Sub

Open in new window

0
 
Brook BraswellApplication Development ManagerCommented:
If your style is 2 then when they user types 3 it would find the first zip code beginning with 3
what are you trying to allow the user to have with style 0 that they would loose with style 2?
0
 
Brook BraswellApplication Development ManagerCommented:
What error are you getting?

The most common is that you are attempting to set the combo box equal to a value that is NOT in the list of items
Example...

box populated with
30012
30014
30016

your recordset has a value of 30015
and you set datasource to recordset

In order to overcome this you must make sure the data matches the available list.
0
 
ZhaolaiCommented:
@Brook1966, by setting the style to 2, the control does not respond to any key event.
0
 
Brook BraswellConnect With a Mentor Application Development ManagerCommented:
not a key event but a click event
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.