Solved

Need a way to count items in listbox

Posted on 2004-03-21
10
323 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

738 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