Create An Access/Quicken-Like Combo Box

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:
XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of

kubernetes logging

Kubernetes Logging: What You Need to Know

Kubernetes from Google is one of the most popular open-source and free container management solutions made to make managing and deploying applications easier. It has a solid architecture that makes

ransomware cyber attack

Why Is Ransomware Such a Major Threat?

One of the most significant cyber threats faced by modern organizations is a ransomware attack. Ransomware attacks have grown in both sophistication and frequency over the past few years, forcing

data dictionary

Tools You Need to Make a Data Dictionary

Data dictionaries are crucial for organizations of all sizes that deal with large amounts of data. they are centralized repositories of all the data in organizations, including metadata such as