Solved

Need a way to count items in listbox

Posted on 2004-03-21
10
319 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
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: 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

895 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

16 Experts available now in Live!

Get 1:1 Help Now