How to Hide Fields when a field is cleared while typing

whitedove

Registered User.
Local time
Today, 02:30
Joined
Jul 14, 2015
Messages
25
I am working on a database. I created a list box (ListBox) that filters record for a form. This list box is controlled by another field (SearchBox) where I type search string.

The ListBox visibility is hidden when the form loads. It only becomes visible when the user starts to type in the SearchBox. The records gets filtered and when the user clicks on the selection, the form goes to the record and the ListBox becomes hidden again.
All this works fine. My problem is for some technical reasons I want the ListBox to show only when there is character in the the SearchBox. When I try to type in the SearchBox the ListBox shows but when I try to clear the SearchBox with backspace the ListBox is still visible

I tried:

Code:
If me.SearchBox = Null Then
me.ListBox.Visible = False
Else
me.ListBox.Visible = True
I also tried
Code:
If  IsNull (SearchBox) Then
Still when I type backspace the ListBox remains visible. Anyone has solution?

Thank you!

EDIT: I forgot to mention that I put this code on the current event of the SearchBox Field.
 
Last edited:
Why don't you try to use the OnChange event of the Search box, that is if it changes the the list box visibility = True.
 
Sorry when I made the edit, I was not in front of the compute by then. What I meant all the code was onchange event but it did not work.
 
Code:
If Nz(Me.SearchBox[COLOR="Blue"].Text[/COLOR], vbNullString)  = vbNullString Then
    Me.ListBox.Visible = False
Else
    Me.ListBox.Visible = True
End If

However, why are you needing to hide it? It might confuse your users.
 
Because I do not want the whole list to show at the same time. That worked, thank you so much.
 
You're welcome!

Because I do not want the whole list to show at the same time.
You stated that the listbox is filtered based on what the user types into Searchbox. Now if the SearchBox control is "blank", then the listbox will have zero items. Isn't this acceptable? Just giving you ideas!
 
No actually it returns all the records that the list box searches when the field is blanks. And it looks through medical records, this is why I prefer it not showing all the list. I made a search box before that can search for exact record but then I preferred doing it with filter list box so it's a little bit easier to search. Thanks for your suggestion. Seriously, you saved me a lot of time. I wish I can learn to build codes like you!
 
If you want it to show no records but still keep the listbox visible, we can work on a solution for that. Otherwise, if you're happy with your current setup, that's fine too.
 
I prefer it this way for now unless you think it is better the other way. I am not sure why would this be confusing?

As I am building the database, I test it with workers with minimal computer knowledge and so far I was told it is pretty straightforward.
 

Users who are viewing this thread

Back
Top Bottom