Solved

Need a way to count items in listbox

Posted on 2004-03-21
10
325 Views
Last Modified: 2010-08-05
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
Comment
Question by:SOOPERDAD
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 10644877
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
 
LVL 54

Expert Comment

by:nico5038
ID: 10644896
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
 
LVL 5

Expert Comment

by:peterpuscas
ID: 10644920
You can count the items in a list with LISTCOUNT property.

mylist.listcount
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:SOOPERDAD
ID: 10644975
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
 
LVL 54

Accepted Solution

by:
nico5038 earned 500 total points
ID: 10644996
Hmm, that won't really help you.
The Yes/No field solution will work for all number of selections without limitation :-)

Nic;o)
0
 

Author Comment

by:SOOPERDAD
ID: 10645058
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
 
LVL 54

Expert Comment

by:nico5038
ID: 10645061
Drop it compacted and zipped in my mail and I'll have a look.

Nic;o)
(Mailaddress: click my membername)
0
 

Author Comment

by:SOOPERDAD
ID: 10645068
What version of Access?

Chris
0
 
LVL 54

Expert Comment

by:nico5038
ID: 10645083
Have A95/A97/A2000/A2002

Nic;o)
0
 
LVL 5

Expert Comment

by:peterpuscas
ID: 10645187
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question