Is it possible to display the contents of a list box in more than one column?
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
list boxes (2000)
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » list boxes (2000)
- This topic has 24 replies, 7 voices, and was last updated 20 years, 5 months ago.
Viewing 1 reply threadAuthorReplies-
WScharlotte
AskWoody Lounger -
WSroberta
AskWoody LoungerNovember 22, 2004 at 5:16 pm #903574Thanks
I have a records of 565 products – I have set up a form with a list box that (thanks to some help from the lounge a while ago) allows more than one product to be selected and then I have a command button which runs a query which runs a report to show details of the products selected.
565 items is quite a lot of rows to scroll through and I was rather hoping I could display them on a form in say 4 columns –
It is not that I want to display more than one field – I want to display one field in more than one column!!!
If anyone has any bright ideas I would be eternally grateful!
-
WSHansV
AskWoody LoungerNovember 22, 2004 at 6:49 pm #903613A list box can display data from different fields in different columns, but not data from one field in different columns.
If there is a way of dividing the products into categories, and if the user will always select one or more products from a single category, you can use cascading list boxes: the user first selects a category from a first list box (or combo box); this makes a second list box display only products from that category.
-
WSHansV
AskWoody LoungerNovember 22, 2004 at 6:49 pm #903614A list box can display data from different fields in different columns, but not data from one field in different columns.
If there is a way of dividing the products into categories, and if the user will always select one or more products from a single category, you can use cascading list boxes: the user first selects a category from a first list box (or combo box); this makes a second list box display only products from that category.
-
WScharlotte
AskWoody Lounger -
WScharlotte
AskWoody Lounger -
WSjohnhutchison
AskWoody LoungerNovember 23, 2004 at 3:36 am #903814 -
WSjohnhutchison
AskWoody LoungerNovember 23, 2004 at 3:36 am #903815 -
WSMarkD
AskWoody LoungerNovember 23, 2004 at 9:19 am #903812(Edited by MarkD on 23-Nov-04 05:19. Replaced attachment – fixed minor bug in code.)
About the only way you might be able to do this is, is to split the records listed in listbox into separate lists, based on some logical (or illogical) criteria. You could then generate the filter string for report by concatenating the selected items from each list. I usually do this for separate fields but no law says you can’t do it for same field. If interested see attached demo database (A2K format). Demo uses Northwind Products table. Open Form1, select multiple items, then preview or print report (in demo, a crude wizard-generated report). Report will be filtered by selected products from each listbox. Clear the listboxes to view all items in report. In this example I simply broke the products into four groups based on alphabet. You could also use categories or some other criteria. The two textboxes on bottom of form show first, the actual “Where” string used to filter report, the second displays a more user-friendly list of the selected items. In actual use you would not display the first textbox, it would remain hidden to users. See form module for code used to generate the strings. Note the ProductID (number) is used to filter report, not actual product name.
You may be able to adapt this technique for your own project.
HTH
-
WSSupport4John
AskWoody Lounger -
WSjohnhutchison
AskWoody LoungerNovember 23, 2004 at 8:51 pm #904173If you have about 550 products don’t you need about 140 per list – ie. 25% rather than 25.
The easy solution is to make fixed breakup based on the name of the product. It doesn’t really matter if the four lists contain different numbers of products.
Select ProductID, ProductName from tblProducts where (productName < 'f") ORDER BY productName;
Select ProductID, ProductName from tblProducts where (productName Between "f" And "M") ORDER BY productName;etc
Do do it dynamically would take a lot more work.
This will get the first list
Select top 25 percent ProductID, ProductName from tblProducts ORDER BY productName;
Select top 25 percent ProductID, ProductName from tblProducts ORDER BY productName Desc;
would get the bottom 25% in reverse order, so you could then have a second query to sort these back into the right order.To get the middle groups, I am not sure. One possibility is to use subqueries..
SELECT TOP 34 PERCENT ProductID, ProductName FROM tblProducts
WHERE (PruductID Not In (select ProductID from qrytop))
ORDER BY productName;where qrytop is the the query that fives the top 25%.
It does not really matter if there is some overlap between the lists, but it does matter if there is a gap between them.
-
WSjohnhutchison
AskWoody LoungerNovember 23, 2004 at 8:51 pm #904174If you have about 550 products don’t you need about 140 per list – ie. 25% rather than 25.
The easy solution is to make fixed breakup based on the name of the product. It doesn’t really matter if the four lists contain different numbers of products.
Select ProductID, ProductName from tblProducts where (productName < 'f") ORDER BY productName;
Select ProductID, ProductName from tblProducts where (productName Between "f" And "M") ORDER BY productName;etc
Do do it dynamically would take a lot more work.
This will get the first list
Select top 25 percent ProductID, ProductName from tblProducts ORDER BY productName;
Select top 25 percent ProductID, ProductName from tblProducts ORDER BY productName Desc;
would get the bottom 25% in reverse order, so you could then have a second query to sort these back into the right order.To get the middle groups, I am not sure. One possibility is to use subqueries..
SELECT TOP 34 PERCENT ProductID, ProductName FROM tblProducts
WHERE (PruductID Not In (select ProductID from qrytop))
ORDER BY productName;where qrytop is the the query that fives the top 25%.
It does not really matter if there is some overlap between the lists, but it does matter if there is a gap between them.
-
WSMarkD
AskWoody LoungerNovember 24, 2004 at 12:48 am #904275If the number of records to list per listbox is to vary dynamically, one approach would be to create “temporary” queries programatically which would then be used to populate the listboxes on form. As test created some queries “manually” using TOP predicate & subqueries (similar to examples John Hutchinson posted) but this quickly became cumbersome – using NOT IN with more than one subquery resulted in very slow queries even with a small number of records. So instead used DAO methods to create the querydefs to return x number of records, based on user input on form. The function that generates the queries first determines the number of queries to create (based on number of records in table, and on value of x) then runs a loop. Excerpt of code:
For n = 1 To lQueryCount
strSQL = "SELECT TOP " & lngRecords & " ProductID, ProductName " & _
"FROM PRODUCTS WHERE ProductID " & _
"In(SELECT TOP " & CStr((lTotalCount - (lngRecords * (n - 1)))) & " " & _
"ProductID FROM PRODUCTS " & _
"ORDER BY ProductName Desc) " & _
"ORDER BY ProductName;"
Set qry = db.CreateQueryDef("Temp" & n, strSQL)
See attached revised demo database (A2K) for full code and details. Note above, to avoid dreaded NOT IN syntax the subquery selects records from the bottom, not top, calculated number of records, by simply sorting products in descending order in subquery. When function called from form to repopulate listboxes, there is little delay, as might be case if using NOT IN. To test, open Form1, enter valid value in the unbound, unlocked textbox, then click “Reset” button to requery listboxes. If number of queries is less than number of listboxes, code clears the “extra” listboxes. The listbox labels are also updated to reflect which records are listed. If actually using this, may want to add code to clean up the “temp” queries when form closes. Or ditch the querydefs & just use SQL strings as RowSource to populate the listboxes.
Hope this gives you some ideas.
-
WSDollyP
AskWoody LoungerNovember 24, 2004 at 12:28 pm #904431The thought of searching through that number of records in a list box …
The original enquiry was for a multi select listbox. I wonder whether the better interface would be single select listbox with its contents filtered according to A B C buttons (Hans did a nice one a while ago). Each selection made could then be added to a temporary table and shown in a second list box. Once all selections had been made, the results would be in the temporary table.
-
WSDollyP
AskWoody LoungerNovember 24, 2004 at 12:28 pm #904432The thought of searching through that number of records in a list box …
The original enquiry was for a multi select listbox. I wonder whether the better interface would be single select listbox with its contents filtered according to A B C buttons (Hans did a nice one a while ago). Each selection made could then be added to a temporary table and shown in a second list box. Once all selections had been made, the results would be in the temporary table.
-
WSSupport4John
AskWoody Lounger -
WSSupport4John
AskWoody Lounger -
WSjohnhutchison
AskWoody LoungerNovember 24, 2004 at 8:15 pm #904750Another idea on this is to have a temp table.
Clear its contents using a Delete query,
Refill with all products using an append query,
delete any records in the top 25% and bottom 25%, (using subqueries]
then select the top and bottom 50% of the remaining records.All this could use fixed queries that could be saved and reused.
-
WSjohnhutchison
AskWoody LoungerNovember 24, 2004 at 8:15 pm #904751Another idea on this is to have a temp table.
Clear its contents using a Delete query,
Refill with all products using an append query,
delete any records in the top 25% and bottom 25%, (using subqueries]
then select the top and bottom 50% of the remaining records.All this could use fixed queries that could be saved and reused.
-
WSMarkD
AskWoody LoungerNovember 24, 2004 at 12:48 am #904276If the number of records to list per listbox is to vary dynamically, one approach would be to create “temporary” queries programatically which would then be used to populate the listboxes on form. As test created some queries “manually” using TOP predicate & subqueries (similar to examples John Hutchinson posted) but this quickly became cumbersome – using NOT IN with more than one subquery resulted in very slow queries even with a small number of records. So instead used DAO methods to create the querydefs to return x number of records, based on user input on form. The function that generates the queries first determines the number of queries to create (based on number of records in table, and on value of x) then runs a loop. Excerpt of code:
For n = 1 To lQueryCount
strSQL = "SELECT TOP " & lngRecords & " ProductID, ProductName " & _
"FROM PRODUCTS WHERE ProductID " & _
"In(SELECT TOP " & CStr((lTotalCount - (lngRecords * (n - 1)))) & " " & _
"ProductID FROM PRODUCTS " & _
"ORDER BY ProductName Desc) " & _
"ORDER BY ProductName;"
Set qry = db.CreateQueryDef("Temp" & n, strSQL)
See attached revised demo database (A2K) for full code and details. Note above, to avoid dreaded NOT IN syntax the subquery selects records from the bottom, not top, calculated number of records, by simply sorting products in descending order in subquery. When function called from form to repopulate listboxes, there is little delay, as might be case if using NOT IN. To test, open Form1, enter valid value in the unbound, unlocked textbox, then click “Reset” button to requery listboxes. If number of queries is less than number of listboxes, code clears the “extra” listboxes. The listbox labels are also updated to reflect which records are listed. If actually using this, may want to add code to clean up the “temp” queries when form closes. Or ditch the querydefs & just use SQL strings as RowSource to populate the listboxes.
Hope this gives you some ideas.
-
-
WSSupport4John
AskWoody Lounger
-
-
WSMarkD
AskWoody LoungerNovember 23, 2004 at 9:19 am #903813(Edited by MarkD on 23-Nov-04 05:19. Replaced attachment – fixed minor bug in code.)
About the only way you might be able to do this is, is to split the records listed in listbox into separate lists, based on some logical (or illogical) criteria. You could then generate the filter string for report by concatenating the selected items from each list. I usually do this for separate fields but no law says you can’t do it for same field. If interested see attached demo database (A2K format). Demo uses Northwind Products table. Open Form1, select multiple items, then preview or print report (in demo, a crude wizard-generated report). Report will be filtered by selected products from each listbox. Clear the listboxes to view all items in report. In this example I simply broke the products into four groups based on alphabet. You could also use categories or some other criteria. The two textboxes on bottom of form show first, the actual “Where” string used to filter report, the second displays a more user-friendly list of the selected items. In actual use you would not display the first textbox, it would remain hidden to users. See form module for code used to generate the strings. Note the ProductID (number) is used to filter report, not actual product name.
You may be able to adapt this technique for your own project.
HTH
-
-
WSroberta
AskWoody LoungerNovember 22, 2004 at 5:16 pm #903575Thanks
I have a records of 565 products – I have set up a form with a list box that (thanks to some help from the lounge a while ago) allows more than one product to be selected and then I have a command button which runs a query which runs a report to show details of the products selected.
565 items is quite a lot of rows to scroll through and I was rather hoping I could display them on a form in say 4 columns –
It is not that I want to display more than one field – I want to display one field in more than one column!!!
If anyone has any bright ideas I would be eternally grateful!
-
-
WScharlotte
AskWoody Lounger
Viewing 1 reply thread -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
No April cumulative update for Win 11 23H2?
by
Peobody
2 hours, 15 minutes ago -
AugLoop.All (TEST Augmentation Loop MSIT)
by
LarryK
28 minutes ago -
Boot Sequence for Dell Optiplex 7070 Tower
by
Serge Carniol
15 hours, 32 minutes ago -
OTT Upgrade Windows 11 to 24H2 on Unsupported Hardware
by
bbearren
19 hours, 4 minutes ago -
Inetpub can be tricked
by
Susan Bradley
20 hours, 24 minutes ago -
How merge Outlook 2016 .pst file w/into newly created Outlook 2024 install .pst?
by
Tex265
17 hours, 10 minutes ago -
FBI 2024 Internet Crime Report
by
Alex5723
22 hours, 54 minutes ago -
Perplexity CEO says its browser will track everything users do online
by
Alex5723
10 hours, 41 minutes ago -
Login issues with Windows Hello
by
CWBillow
1 day, 9 hours ago -
How to get into a manual setup screen in 2024 Outlook classic?
by
Tex265
21 hours, 53 minutes ago -
Linux : ARMO rootkit “Curing”
by
Alex5723
1 day, 21 hours ago -
Employee monitoring app leaks 21 million screenshots in real time
by
Alex5723
1 day, 21 hours ago -
Google AI is now hallucinating idioms
by
Alex5723
1 day, 22 hours ago -
april update
by
69800
2 hours, 28 minutes ago -
Windows 11 Insider Preview build 27842 released to Canary
by
joep517
1 day, 23 hours ago -
Quick Fix for Slowing File Explorer
by
Drcard:))
1 day, 23 hours ago -
WuMgr not loading?
by
LHiggins
19 hours, 1 minute ago -
Word crashes when accessing Help
by
CWBillow
1 day, 3 hours ago -
New Microsoft Nag — Danger! Danger! sign-in to your Microsoft Account
by
EricB
1 day, 22 hours ago -
Blank Inetpub folder
by
Susan Bradley
1 day, 20 hours ago -
Google : Extended Repair Program for Pixel 7a
by
Alex5723
2 days, 9 hours ago -
Updates seem to have broken Microsoft Edge
by
rebop2020
1 day, 19 hours ago -
Wait command?
by
CWBillow
2 days, 2 hours ago -
Malwarebytes 5 Free version manual platform updates
by
Bob99
2 days, 16 hours ago -
inetpub : Microsoft’s patch for CVE-2025–21204 introduces vulnerability
by
Alex5723
2 days, 22 hours ago -
Windows 10 finally gets fix
by
Susan Bradley
3 days, 7 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.04.09.545
by
Alex5723
3 days, 8 hours ago -
How to use Skype after May?
by
Joann
1 day, 17 hours ago -
Win 7 MS Essentials suddenly not showing number of items scanned.
by
Oldtimer
3 days, 3 hours ago -
France : A law requiring messaging apps to implement a backdoor ..
by
Alex5723
3 days, 21 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.