Solved

DBCombo automatic typeahead search

Posted on 1998-10-08
11
192 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
[X]
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
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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.
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.
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…
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…
Suggested Courses
Course of the Month8 days, 13 hours left to enroll

617 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