Solved

DBCombo automatic typeahead search

Posted on 1998-10-08
11
184 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
ID: 1438848
Edited text of question
0
 
LVL 14

Expert Comment

by:waty
ID: 1438849
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
ID: 1438850
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
ID: 1438851
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
ID: 1438852
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
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.

 
LVL 1

Author Comment

by:cheechew
ID: 1438853
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
ID: 1438854
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
ID: 1438855
Mirkwood,
 Sorry, this is not what I want. I want something much more than that.
0
 
LVL 13

Expert Comment

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

Accepted Solution

by:
Mirkwood earned 200 total points
ID: 1438857
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
ID: 1438858

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

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

920 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

14 Experts available now in Live!

Get 1:1 Help Now