Create An Access/Quicken-Like Combo Box

This example shows how to make a combo box act like those found in Quickenor Microsoft Access, without using a third-party VBX. As each characteris typed, the elements in the combo box are searched and, if a match isfound, retrieved. If a match is not found, the original typed text is restored.The only code needed resides in the KeyUp event of a combo box called combo1.The combo box is sorted alphabetically, so it stops on the first alphabeticalmatch. I use the SendMessage API to turn the redraw of the combo box offand then on when the search is complete. Here are the form-level declarations for the combo box:

 Dim strCombo As StringConst WM_SETREDRAW = &HBConst KEY_A = 65Const KEY_Z = 90Declare Function SendMessage Lib "User" _	(ByVal hWnd As Integer, _	ByVal wMsg As Integer, _	ByVal wParam As Integer, _	lParam As Any) As Long

The code in the KeyUp event looks like this:

 Dim x%Dim strTemp$Dim nRet&If Keycode >= KEY_A And Keycode <= KEY_Z Then'only look at letters A-Z	strTemp = combo1.Text	If Len(strTemp) = 1 Then strCombo = strTemp	nRet& = SendMessage(combo1.hWnd, _		WM_SETREDRAW, False, 0&)	For x = 0 To (combo1.ListCount - 1)		If UCase((strTemp & _		Mid$(combo1.List(x), _		Len(strTemp) + 1))) =UCase(combo1.List(x)) Then		combo1.ListIndex = x		combo1.Text = combo1.List(x)		combo1.SelStart = Len(strTemp)		combo1.SelLength = _			Len(combo1.Text) - (Len(strTemp))		strCombo = strCombo & _			Mid$(strTemp, Len(strCombo) + 1)		Exit For	Else		If InStr(UCase(strTemp), _			UCase(strCombo)) Then			strCombo = strCombo & _			Mid$(strTemp, Len(strCombo) + 1)			combo1.Text = strCombo			combo1.SelStart = Len(combo1.Text)		Else			strCombo = strTemp		End If	End IfNextnRet& = SendMessage(combo1.hWnd, _	WM_SETREDRAW, True, 0&)End If
Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a