devxlogo

ComboBox Autofill

ComboBox Autofill

ComboBox controls, out of the box, don’t help complete phrases as they are typed in. The sample code below accomplishes that task. cmb is the name of the ComboBox to which Autofill is added. mbNoManualChange is a modular level variable used as a status flag, preventing the UpdateText routine from raising the control’s change event (avoiding circular references). mbNoManualChange also blocks Autofill when Delete or Backspace keys are used.

 Dim mbNoManualChange As Boolean     Private Sub cmb_Change()         On Error GoTo Routine_Error         If Not mbNoManualChange Then UpdateText     Routine_Error:         If Err.Number <> 0 Then             MsgBox Err.Description, vbInformation, Err.Sourc             Err.Clear         End If     End Sub     Private Sub cmb_KeyDown(KeyCode As Integer, Shift As Integer)         On Error GoTo Routine_Error         Select Case KeyCode             Case vbKeyDelete, vbKeyBack: mbNoManualChange = True             Case Else: mbNoManualChange = False         End Select     Routine_Error:         If Err.Number <> 0 Then             MsgBox Err.Description, vbInformation, Err.Sourc             Err.Clear         End If     End Sub     Private Sub UpdateText()         On Error GoTo Routine_Error         Dim sTypedText As String         Dim sSelectText As String         Dim lCounter As Long         'Suspend Status         mbNoManualChange = True         'Update Combobox Text         With cmb             sTypedText = Replace(.Text, .SelText,

See also  Monetize TikTok For Your Business
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist