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
Solved

DBCombo automatic typeahead search

Posted on 1998-10-08
11
188 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

808 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