Link to home
Start Free TrialLog in
Avatar of Roman F
Roman FFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Brook Braswell
Brook Braswell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Roman F

ASKER

Thank you, but anybody knows how to validate through the code?
I need my style=0
What do you mean by "validate through the code"?
Combo1.Style = 0
Avatar of Roman F

ASKER

no, like something preventing the user type in, using let say If statements...
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?
Avatar of Roman F

ASKER

I know that...
but for what ever reason i am getting the error, when i am changing the style =2...
Try this:
Private Sub Combo1_KeyPress(KeyAscii As Integer)
    KeyAscii = 0
End Sub

Open in new window

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?
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.
@Brook1966, by setting the style to 2, the control does not respond to any key event.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial