Solved

special combobox controls

Posted on 1998-08-31
5
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

739 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