Solved

autocomplete

Posted on 2004-03-22
5
708 Views
Last Modified: 2010-08-05
How to make my combo box autocomplete like  in Ms access
0
Comment
Question by:jone5
5 Comments
 
LVL 48

Expert Comment

by:Mikal613
ID: 10650729
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 55 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 70 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

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

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

16 Experts available now in Live!

Get 1:1 Help Now