Results 1 to 8 of 8
  1. #1
    prsaddict is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    4

    Question Show combobox when ANY text is entered into a textfield

    Howdy! I've spent several hours working on this, but haven't been able to land the solution. I hope your expertise can point me in the right direction!

    I have a continuous form that has an optional search that uses a combobox. My goal is for the combobox to remain hidden until ANY text is entered into the textbox.

    The best I can do right now is using the textbox's AfterUpdate event to trigger the if/then code that displays the combobox. I've got this working, but it's frustrating, because I have to "update" the textbox by either tabbing out or hitting "enter". I really want the combobox to appear as soon as I begin typing text into the textbox.

    To complicate it a step further, by design I want the combobox to disappear when the textbox is cleared.

    Here's the current state of my code. Note that "OmniSearch" refers to the textbox, and "lst_Leaders" is the combobox.

    Private Sub Omnisearch_AfterUpdate()
    Call Form_Current


    End Sub

    Private Sub Form_Current
    If IsNull(Me.OmniSearch) Then
    Me.lst_Leaders.Visible = False
    Else
    Me.lst_Leaders.Visible = True
    End If
    End Sub

    Using this code works only after the textfield is updated (hence the AfterUpdate sub), but I can't for the life of me figure out how to accomplish this by only entering text into the textfield (without tabbing away or pressing enter).

    I tried using the On Change event procedure, but I couldn't get it working. I believe this is because the content of the textbox directly affects the content of the combobox, and I read on MS website that this can cause conflicts.

    Any help is appreciated! Thanks so much.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The change event would be the place to do what you want, but you have to use the Text property:

    Me.OmniSearch.Text

    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    prsaddict is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    4
    Beautiful! Thank you so much, pbaldy. You were spot on!

    I moved the code to the change event and added the .text property. The combobox is now appearing as soon as text is entered.

    The downside now is, if I enter text and then clear it (with escape or backspace), the combobox doesn't hide. I'm looking into this now. If you have any quick tip, I'd appreciate it!

    Thanks again for your quick and accurate feedback!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You need to test for both Null and zero length string. One way:

    If Len(Me.OmniSearch.Text & vbNullString) = 0 Then
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    prsaddict is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jan 2016
    Posts
    4
    You, sir, are a steely-eyed missile man.
    Done and done.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    LOL! I've been called a lot of things; that's a new one.

    Happy to help, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    beesee is offline Novice
    Windows 7 64bit Access 2002
    Join Date
    Jan 2016
    Location
    Vancouver, BC
    Posts
    15
    Thanks prsaddict for this post, and the answers by pbaldy. This helps me greatly on a filter form I am designing.

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Glad it helped you!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 08-04-2015, 08:42 AM
  2. Replies: 8
    Last Post: 10-09-2014, 01:31 AM
  3. Form won't show entered records
    By FMAlanbrooke in forum Forms
    Replies: 4
    Last Post: 09-16-2014, 08:38 PM
  4. Show The Last 10 Records entered on Form
    By athyeh in forum Forms
    Replies: 2
    Last Post: 11-28-2013, 09:51 AM
  5. Replies: 1
    Last Post: 01-26-2012, 05:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums