Solved

autocomplete

Posted on 2004-03-22
5
694 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
Comment Utility
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 55 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thank you all
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

762 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

9 Experts available now in Live!

Get 1:1 Help Now