Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1078739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:46:02+00:00 2026-05-16T21:46:02+00:00

I have a form in Excel with a combo box control. I want the

  • 0

I have a form in Excel with a combo box control. I want the values to be filled from a database table when the combo box is opened using what has already been typed in as a LIKE criteria. This is the code I have so far for the DropButtonClick event to achieve this.

Private Sub cboVariety_DropButtonClick()
    Static search_text As String
    Static is_open As Boolean
    Dim rs As New Recordset

    If is_open Then
        is_open = False
        Exit Sub
    End If
    is_open = True

    If search_text = cboVariety Then Exit Sub
    search_text = cboVariety

    cboVariety.Clear
    cboVariety.AddItem search_text
    If Len(search_text) > 2 Then
        rs.Open _
            "SELECT Name FROM tbl_Varieties " & _
            "WHERE Name LIKE '%" & search_text & "%' " & _
            "ORDER BY Name", connect_string, adOpenStatic
        Do Until rs.EOF
            If rs!Name <> search_text Then cboVariety.AddItem rs!Name
            rs.MoveNext
        Loop
        rs.Close
    End If
End Sub

The problem is that the DropButtonClick event fires both when the combo box is opened and when it is closed. If this sub executes when the combo box is closing, the code that clears the combo box causes the user’s selection to be erased.

I’m trying to tell when the box is closed using the is_open variable, which alternates between true and false each time the event sub is executed. This seems like a brittle solution to the problem. Is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:46:03+00:00Added an answer on May 16, 2026 at 9:46 pm

    I found a simple way to solve this. It doesn’t seem like it should work, but if I just reassign the value of the combo box after rebuilding the list, it doesn’t discard the value that is selected.

    Private Sub cboVariety_DropButtonClick()
        Static search_text As String
        Dim rs As New Recordset
    
        If search_text = cboVariety Then Exit Sub
        search_text = cboVariety
    
        cboVariety.Clear
        If Len(search_text) > 2 Then
            rs.Open _
                "SELECT Name FROM tbl_Varieties " & _
                "WHERE Name LIKE '%" & search_text & "%' " & _
                "ORDER BY Name", connect_string, adOpenStatic
            Do Until rs.EOF
                cboVariety.AddItem rs!Name
                rs.MoveNext
            Loop
            rs.Close
        End If
    
        '' Reassign cboVariety in case this event was triggered by combo close
        cboVariety = search_text
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which spawns from an excel add-in written with VSTO. I
i want to open notepad, word or excel files from sql server using some
I have a form in C# that has a button that, when clicked, I
I have a form in which people will be entering dollar values. Possible inputs:
I have a form that contains a GridView control which is databound to an
I have a form with 3 textboxes and 1 button. textbox1 has tab index
Okay all, I have a form that I want users to fill out. When
I have the following code to insert items into a MySQL database from an
I have a form that users are able to fill in and want to
I have a form <form name=frmMain method=POST action=processUpload.jsp enctype=multipart/form-data> <p align=center><table border=1 align=center width=90%

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.