Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 447
  • Last Modified:

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
0
rfedorov
Asked:
rfedorov
  • 5
  • 4
  • 3
  • +1
4 Solutions
 
Brook BraswellApplication Development ManagerCommented:
Make the Combo Box a style of 2 - DropDown List
0
 
Taki EliasSoftware EngineerCommented:
Check The Properties Of Combo box Style > Select ? Drop Down list
0
 
ZhaolaiCommented:
This is what you need to set in visual mode:
ScreenShot.png
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 BraswellApplication Development ManagerCommented:
not a key event but a click event
0

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 5
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now