Solved

DBCombo automatic typeahead search

Posted on 1998-10-08
11
183 Views
Last Modified: 2008-02-20
Can I create an effect that when I type a few letters of the beginning of a word in a combobox, it will automatically prompt the word that match the first few letters that I typed from the item list?

This question is related from the question from
http://www.experts-exchange.com/topics/comp/lang/visualbasic/Q.10065601

If u can give me the right answer, I guarantee u with satisfaction bonus point.
0
Comment
Question by:cheechew
11 Comments
 
LVL 1

Author Comment

by:cheechew
Comment Utility
Edited text of question
0
 
LVL 14

Expert Comment

by:waty
Comment Utility
Use the following :

Private Sub Combo1_KeyPress(KeyAscii As Integer)

   Dim nLine      As Long
 
   nLine = CBLFind(Combo1, Combo1.Text & Chr$(KeyAscii), 0)
     
End Sub


Function CBLFind(CBL As Control, strToFind As String, nFirst As Long) As Long
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 8/10/98
   ' * Time             : 17:08
   ' * Module Name      : ListBox_Module
   ' * Module Filename  : D:\TWA\Lib\CBLSTBOX.BAS
   ' * Procedure Name   : CBLFind
   ' * Parameters       :
   ' *                    CBL As Control
   ' *                    strToFind As String
   ' *                    nFirst As Long
   ' **********************************************************************
   ' * Comments         : Search a string in a combo or in a listbox
   ' * Return the found line, otherwise -1
   ' *
   ' **********************************************************************

   Dim nIndex  As Long
   Dim nCount  As Long
   Dim nLength As Long
   Dim szItem  As String

   nCount = CBL.ListCount
   nLength = Len(strToFind)

   CBLFind = -1
   strToFind = UCase(strToFind)

   If (nCount = -1) Or (nLength = 0) Then
      Exit Function
   End If

   If (nFirst >= 0) Then
      For nIndex = nFirst To nCount
         szItem = UCase(CBL.List(nIndex))
         If Len(szItem) = nLength Then
            If szItem = strToFind Then
               CBLFind = nIndex
               Exit For
            End If
         End If
      Next
   Else
      For nIndex = Abs(nFirst) To 0 Step -1
         szItem = UCase(CBL.List(nIndex))
         If Len(szItem) = nLength Then
            If szItem = strToFind Then
               CBLFind = nIndex
               Exit For
            End If
         End If
      Next
   End If

End Function

0
 
LVL 1

Author Comment

by:cheechew
Comment Utility
I think this will be very useful to me, but if u can do it on the DBCombo box, it would be much better. Please give ur solution on DBCombo box.
0
 
LVL 1

Author Comment

by:cheechew
Comment Utility
I have already tried out the code. It is not works axactly as what I want. Anyway thank u for your afford of trying.
0
 
LVL 9

Expert Comment

by:Dalin
Comment Utility
cheechchew,
Try this. Let me know if you have any questions.
Regards
Dalin


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

Const CB_ERR = -1
Const CB_FINDSTRING = &H14C

'Add the sub

Sub sMatchEntry(cbo As ComboBox, KeyAscii As Integer)
  Dim sBuffer As String
  Dim lRetVal As Long

  sBuffer = Left(cbo.Text, cbo.SelStart) & Chr(KeyAscii)
  lRetVal = SendMessage((cbo.hWnd), CB_FINDSTRING, _
  -1, ByVal sBuffer)
  If lRetVal <> CB_ERR Then
    With cbo
      .ListIndex = lRetVal
      .Text = .List(lRetVal)
      .SelStart = Len(sBuffer)
      .SelLength = Len(.Text)
    End With
    KeyAscii = 0
  End If
End Sub

' in the KeyPress Event add:

Private Sub Combo1_KeyPress(KeyAscii As Integer)
  sMatchEntry Combo1, KeyAscii
End Sub
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:cheechew
Comment Utility
thank you dalin, although u provide good answer but what I want is in dbcombo and not combo.
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
I could be very confused but I think that it will just work when you set the following properties.

set Dbcombo1.datasource = data1
DbCombo1.Datafield = "Author"
DbCombo1.ListField = "Author"
DbCombo1.matchentry = 1
DbCombo1.style = 2

0
 
LVL 1

Author Comment

by:cheechew
Comment Utility
Mirkwood,
 Sorry, this is not what I want. I want something much more than that.
0
 
LVL 13

Expert Comment

by:Mirkwood
Comment Utility
Have you tried what it does. It seems to do what you described...
0
 
LVL 13

Accepted Solution

by:
Mirkwood earned 200 total points
Comment Utility
I dont want to be rude, but please describe what you want and why the code was not sufficient.
It does for DBCombo what Waty and Dalins code does for Combo.
 

0
 
LVL 4

Expert Comment

by:tmack
Comment Utility

Set your DBcombo properties to this:
dbcombo.matchentry = dblextendedmatching

By setting your property to this will anable the user to type in the first couple letters of an object thats populated in a dbcombo and you will automatically go to that object the most closly matches that string.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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 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…

743 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

16 Experts available now in Live!

Get 1:1 Help Now