• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

Text box - Limit to list

Hi,
I need to limit the entry in the textbox to the list only. So that if user types somethign into textbox that's not in the list, it should pop up errro while tabing out from that control. I know, access has property called "limit to list". Just need to find same for VB.

Thanks!
Hirak
0
hirak1977
Asked:
hirak1977
  • 7
  • 5
1 Solution
 
diegojserranoCommented:
in vb you will have to write that behavior.
i think you may better use a combobox  with style = dropdowncombo
0
 
hirak1977Author Commented:
I m using the same style - dropdowncombo.

0
 
sirbountyCommented:
Can you use a combo box instead?
Set the style to Dropdown list - then the user can only select what's in the list - not type in anything...
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
hirak1977Author Commented:
No I can not do that either. I have written the behaviour to narrow down the list as you type in the combo box. I had to do it bcoz some of users wanted to type in rather than scrolling down to select from 10000 items.

0
 
sirbountyCommented:
Is it a text box or combo box?
0
 
hirak1977Author Commented:
OH my bad!! It's my mistake. It's combo box.
0
 
sirbountyCommented:
Okay - now I guess I'm really confused...

You have a combo box that you can't set to drop down list that you want to prevent users from entering text into?
0
 
hirak1977Author Commented:
Yes, that true. Thing is when you set combo box to drop down list. you can just type in first character.It just looks for first character. With my below code, you can type in as many character you want.  But problem is I want it to give me an error if some types in wrong entry which is not in the list and still tries to save data.


Private Sub load_KeyPress(KeyAscii As Integer)
Dim CB As Long
    Dim FindString As String

    If KeyAscii < 32 Or KeyAscii > 127 Then Exit Sub

    If load.SelLength = 0 Then
        FindString = load.Text & Chr$(KeyAscii)
    Else
        FindString = Left$(load.Text, load.SelStart) & Chr$(KeyAscii)
    End If

    CB = SendMessage(load.hwnd, CB_FINDSTRING, -1, ByVal FindString)

    If CB <> CB_ERR Then
        load.ListIndex = CB
        load.SelStart = Len(FindString)
        load.SelLength = Len(load.Text) - load.SelStart
    End If
    KeyAscii = 0
End Sub

0
 
sirbountyCommented:
I think you'll need to combine all of your combo data into a string...

For x = 0 To load.ListCount - 1
    strCombo = load.List(x) & "," & strCombo
Next x

Then, you can check what is selected against that string

if instr(1,strcombo,load.List(load.ListIndex)) < 1 then
  msgbox "Error"
End if
0
 
hirak1977Author Commented:
POINT ARE YOURS,
THANKS!
0
 
hirak1977Author Commented:
POINT ARE YOURS,
THANKS!
0
 
hirak1977Author Commented:
POINT ARE YOURS,
THANKS!
0
 
sirbountyCommented:
Well, thank you, thank you, thank you...
:D
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now