Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

autocomplete

Posted on 2004-03-22
5
Medium Priority
?
770 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
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…
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…
Suggested Courses

609 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