Solved

Need a way to count items in listbox

Posted on 2004-03-21
10
318 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
  • 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
 

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now