Solved

Text box - Limit to list

Posted on 2004-04-13
13
321 Views
Last Modified: 2010-05-02
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
Comment
Question by:hirak1977
  • 7
  • 5
13 Comments
 
LVL 3

Expert Comment

by:diegojserrano
ID: 10815707
in vb you will have to write that behavior.
i think you may better use a combobox  with style = dropdowncombo
0
 
LVL 1

Author Comment

by:hirak1977
ID: 10815728
I m using the same style - dropdowncombo.

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10815732
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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 1

Author Comment

by:hirak1977
ID: 10815763
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
 
LVL 67

Expert Comment

by:sirbounty
ID: 10815785
Is it a text box or combo box?
0
 
LVL 1

Author Comment

by:hirak1977
ID: 10815804
OH my bad!! It's my mistake. It's combo box.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10815814
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
 
LVL 1

Author Comment

by:hirak1977
ID: 10815883
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
 
LVL 67

Accepted Solution

by:
sirbounty earned 75 total points
ID: 10815999
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
 
LVL 1

Author Comment

by:hirak1977
ID: 10816064
POINT ARE YOURS,
THANKS!
0
 
LVL 1

Author Comment

by:hirak1977
ID: 10816066
POINT ARE YOURS,
THANKS!
0
 
LVL 1

Author Comment

by:hirak1977
ID: 10816067
POINT ARE YOURS,
THANKS!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 10816354
Well, thank you, thank you, thank you...
:D
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Updates not working for MS Windows 7 12 164
VB6 Compile Compatibility Issue 4 102
Spell Check in VB6 13 112
Child Form in front 4 46
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question