Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DBCombo automatic typeahead search

Posted on 1998-10-08
11
Medium Priority
?
196 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

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

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…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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 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…
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

972 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