Solved

special combobox controls

Posted on 1998-08-31
5
218 Views
Last Modified: 2012-06-27
I need a combobox which works like the combobox used by MS Outlook to select a person to send a meassage "To:".  It has a textbox above a listbox.  As text is entered into the textbox, a cursor moves down the listbox, highlighting the closest selection from the list.  A simple combobox is close, but it does not highlight the closest match.  I match the closest selection to retrieve data from my database and I don't want to query with incomplete input.
0
Comment
Question by:lrstratton
5 Comments
 

Expert Comment

by:bad_ima
ID: 1432134
Use the following code , (changing the combo1 with the name of your combobox) or try using the combobox or listbox from the "Microsoft Forms 2.0 Library".
P.S. You can modify this code to be with a textbox & listbox like in Outlook ... Just keep the idea ...



Dim strCombo As String
private Const WM_SETREDRAW = &HB
Private Const KEY_A = 65
Private Const KEY_Z = 90

Private Declare Function SendMessage Lib "User" _
       (ByVal hWnd As Integer, _
       ByVal wMsg As Integer, _
       ByVal wParam As Integer, _
       lParam As Any) As Long

Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim x%
Dim strTemp$
Dim nRet&
If Keycode >= KEY_A And Keycode <= KEY_Z Then
'     'only look at letters A-Z
strTemp = combo1.Text
If Len(strTemp) = 1 Then strCombo = strTemp
nRet& = SendMessage(combo1.hWnd, _
WM_SETREDRAW, False, 0&)

       For x = 0 To (combo1.ListCount - 1)
              If UCase((strTemp & _
              Mid$(combo1.List(x), _
              Len(strTemp) + 1))) =
              UCase(combo1.List(x)) Then
              combo1.ListIndex = x
              combo1.Text = combo1.List(x)
              combo1.SelStart = Len(strTemp)
              combo1.SelLength = _
              Len(combo1.Text) - (Len(strTemp))
              strCombo = strCombo & _
              Mid$(strTemp, Len(strCombo) + 1)
              Exit For
       Else
              If InStr(UCase(strTemp), _
              UCase(strCombo)) Then
              strCombo = strCombo & _
              Mid$(strTemp, Len(strCombo) + 1)
              combo1.Text = strCombo
              combo1.SelStart = Len(combo1.Text)
       Else
              strCombo = strTemp
       End If

End If

Next

nRet& = SendMessage(combo1.hWnd, _
WM_SETREDRAW, True, 0&)
End If

End Sub

0
 

Author Comment

by:lrstratton
ID: 1432135
When I try your code, I get the message:

Run-time error '48':

File not found: User

I do not have a user.dll in my system directory.  I am running Windows 95 and Visual Basic Version 5.  Should the Declare Function user "User32"?  When I do that, I get the message:

Run-time error '453':

Can't find DLL entry point SendMessage in User32

0
 
LVL 2

Expert Comment

by:shchuka
ID: 1432136
I believe the code bad_ima gave you was from 16-bit VB.  The correct declaration for the SendMessage API should be

Private Declare Function SendMessage alias "SendMessageA" Lib "User32" _
            (ByVal hWnd As Long, _
            ByVal wMsg As Long, _
            ByVal wParam As Long, _
            lParam As Any) As Long

Good luck.
0
 

Expert Comment

by:bad_ima
ID: 1432137
Sorry, that's right... I had it in a database and I forgot about this detail , which is realy important.

0
 

Accepted Solution

by:
nbishop earned 100 total points
ID: 1432138
check Microsoft KB#Q161161
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now