Solved

autocomplete

Posted on 2004-03-22
5
752 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 52

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

724 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