?
Solved

autocomplete

Posted on 2004-03-22
5
Medium Priority
?
758 Views
Last Modified: 2010-08-05
How to make my combo box autocomplete like  in Ms access
0
Comment
Question by:jone5
[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
5 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 10650729
0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 165 total points
ID: 10650779
An Example on web here:

'Combo - Using the auto-complete function
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

Private Const CB_FINDSTRING = &H14C
Private Const CB_ERR = (-1)

Private Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const CB_SETCURSEL = &H14E
Private m_bEditFromCode As Boolean

Private Sub Form_Load()
    With Combo1
        .AddItem "VB Square"
        .AddItem "http://www.vbsquare.com"
        .AddItem "VB World"
        .AddItem "http://www.vb-world.net"
    End With
End Sub

Private Sub Combo1_Change()
    Dim i As Long, j As Long
    Dim strPartial As String, strTotal As String

    If m_bEditFromCode Then
        m_bEditFromCode = False
        Exit Sub
    End If

    With Combo1
        strPartial = .Text
        i = SendMessage(.hwnd, CB_FINDSTRING, -1, ByVal strPartial)
        If i <> CB_ERR Then
            strTotal = .List(i)
            j = Len(strTotal) - Len(strPartial)
            If j <> 0 Then
                m_bEditFromCode = True
                .SelText = Right$(strTotal, j)

                'Select unmatched characters
                .SelStart = Len(strPartial)
                .SelLength = j
            End If
        End If
    End With
End Sub

Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case vbKeyDelete
        m_bEditFromCode = True
    Case vbKeyBack
        m_bEditFromCode = True
    End Select
End Sub

Hope this helps
0
 
LVL 5

Expert Comment

by:jayeshshah
ID: 10650921
change the type to a standard combobox and in the Gotfocus event write the below code

Sendkeys "{F4}"

This should work like Autocomplete.

Regards

Jayesh
0
 
LVL 1

Assisted Solution

by:ayada
ayada earned 210 total points
ID: 10651211
in module...>

Public Const CB_FINDSTRING = &H14C
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

in...> Sub Combo1_KeyPress(KeyAscii As Integer)
Dim lng As Long, intPos As Integer, intLength As Integer
With Combo1
If KeyAscii = 8 Then
If .SelStart = 0 Then Exit Sub
.SelStart = .SelStart - 1
.SelLength = 32000
.SelText = ""
Else
.SelText = Chr(KeyAscii)
End If
KeyAscii = 0
lng= SendMessage(.hwnd, CB_FINDSTRING, 0, ByVal .Text)
If lng = -1 Then Exit Sub
intPos = .SelStart
intLength = Len(.List(lng)) - Len(.Text)
.SelText = .SelText & Right(.List(lng), intLength)
.SelStart = intPos
.SelLength = intLength
End With


0
 

Author Comment

by:jone5
ID: 10652639
thank you all
0

Featured Post

Industry Leaders: 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 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

752 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