Solved

special combobox controls

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

932 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

15 Experts available now in Live!

Get 1:1 Help Now