Solved

special combobox controls

Posted on 1998-08-31
5
224 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

623 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