By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,940 Members | 611 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,940 IT Pros & Developers. It's quick & easy.

How to have a "All" or "No selection means all" option on my Listbox Filter?

P: 1
Hello everyone!

I'm learning VBA on my own sort of as I go along, and I've been doing an okay job but I'm stuck on one thing. So far I have created a form with a list box that acts as a filter to a query. If you click in "cities" Yonkers, Woodside and Jamaica and then the filter button - only properties with those cities come up.

I want an "All" button or a condition that states that if none are selected, select all but I cant figure it out or find anything that works for me.

Here is my code right now:

Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunSQL ("Delete * from cities")
  2. For x = o To Me.CityList.ListCount - 1
  3.     If Me.CityList.Selected(x) = True Then
  4.         DoCmd.RunSQL ("Insert into cities values('" & _
  5.             Me.CityList.ItemData(x) & "')")
  6.     End If
  7. Next

There is no way Im doing it the simplest, but it's working for me with this exception (I learned it from a video).

Cities is a Table seperate from my properties table (which has all information) - from what I can tell, based on the filter it lists only those selected.
CityList is the list box, pulling options from "All Cities" A query of every City through a group by function.

Many Thanks! If you need any clarification let me know and Ill try my best to respond helpfully!
Feb 28 '17 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 1,430
Sorry to say that looks messy, though I'm far from clear on what you are trying to achieve.

A good start would be to give an outline of your 2 tables and their relationship and exactly what information you are trying to obtain.

Mar 1 '17 #2

Post your reply

Sign in to post your reply or Sign up for a free account.