• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 333
  • Last Modified:

Need a way to count items in listbox

Hiya,
Here is what happens. A user doubleclicks on names in list one, doing so creates an sql statement that fills list 2 with all of the names the user selected. Since you can only have 99 "And" or "Or" statements in a where clause, I need to be able to count the items in list 2 and give the user a message when that limit is reached. :)

Chris
0
SOOPERDAD
Asked:
SOOPERDAD
  • 4
  • 3
  • 2
  • +1
1 Solution
 
peter57rCommented:
Hello SOOPERDAD,

Instead of using ORs you could look at using the In() structure in your criteria
In ("aaa","bbb","ccc"","ddd") etc  where aaa, bbb etc are the selections from the listbox.

Pete
0
 
nico5038Commented:
An easy workaround can be to add a Yes/No field to the original table the selection is based on.
In the doubleclick event use an update query to set the field to "Yes" or "No" depending on the value (a toggle) to make sure the user can switch it off when selected the wrong name.

The "doublclick" update should look like:
currentdb.execute ("UPDATE tblYourTable SET YesNoField = NOT ([YesNoField]) WHERE Name='" & me.listbox & "';")
me.refresh

To start you can reset all in the OnOpen of the form with:
currentdb.execute ("UPDATE tblYourTable SET YesNoField =False;")

When you also add the YesNo to the listbox the user will see also the selected items.

Finally show in the selected listbox (2) only rows with the YesNoField set to "Yes"

Idea ?

Nic;o)
0
 
peterpuscasCommented:
You can count the items in a list with LISTCOUNT property.

mylist.listcount
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
SOOPERDADAuthor Commented:
peter,
How would i use that In() in a sql statement? i'm clueless, and still waiting on my sql and vba books to arrive from the states,, hehe.

Chris
0
 
nico5038Commented:
Hmm, that won't really help you.
The Yes/No field solution will work for all number of selections without limitation :-)

Nic;o)
0
 
SOOPERDADAuthor Commented:
I'd be glad to post another question just to get some kind of explanation of how and where to use the In() structure, I want to learn about everything, and that one sounds useful :)

Nic, your answer is great, except now i have to restructure the form, get rid of the code that builds the sql statement to populate the second list,, get rid of the textboxes that hold the strings, blah, blah, blah,, lol. thanks a lot! ;)
Would you be willing to take a look at my form and tell me if the way I'm doing it is wrong? I don't want sloppy work here, but I'm limited by my very small set of skills...

Chris
0
 
nico5038Commented:
Drop it compacted and zipped in my mail and I'll have a look.

Nic;o)
(Mailaddress: click my membername)
0
 
SOOPERDADAuthor Commented:
What version of Access?

Chris
0
 
nico5038Commented:
Have A95/A97/A2000/A2002

Nic;o)
0
 
peterpuscasCommented:
SELECT *  FROM tblDate   WHERE id  in(1, 2, 3);

SELECT *  FROM tblDate   WHERE name  in("John", "Mike", "Kyle");

SELECT *  FROM tblDate   WHERE mydate  in(#01/01/04#, #03/03/04");

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now