Is it possible to display the contents of a list box in more than one column?
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
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, 4 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
-
HP Pavilion Will Not Wake Up After Being Idle for Longer Period
by
WSwalterwood44
2 hours, 58 minutes ago -
Make a Windows 11 Local Account Passwordless
by
Drcard:))
2 hours, 32 minutes ago -
Ubuntu 25.04 (Plucky Puffin)
by
Alex5723
6 hours, 7 minutes ago -
24H2 fixed??
by
CWBillow
8 hours, 48 minutes ago -
Uninstalr Updates
by
jv16
11 hours, 16 minutes ago -
Apple zero days for April
by
Susan Bradley
16 hours, 40 minutes ago -
CVE program gets last-minute funding from CISA – and maybe a new home
by
Nibbled To Death By Ducks
22 hours, 11 minutes ago -
Whistleblower describes DOGE IT dept rumpus at America’s labor watchdog
by
Nibbled To Death By Ducks
1 day, 10 hours ago -
Seeing BSOD’s on 24H2?
by
Susan Bradley
16 hours, 55 minutes ago -
TUT For Private Llama LLM, Local Installation and Isolated from the Internet.
by
bbearren
1 day ago -
Upgrade from Windows 10 to 11
by
Holdsworth8
1 day, 18 hours ago -
Microsoft : AI-powered deception: Emerging fraud threats and countermeasures
by
Alex5723
1 day, 21 hours ago -
0patch
by
WSjcgc50
22 hours, 29 minutes ago -
Devices might encounter blue screen exception with the recent Windows updates
by
Susan Bradley
1 day, 14 hours ago -
Windows 11 Insider Preview Build 22631.5261 (23H2) released to Release Preview
by
joep517
2 days ago -
Problem opening image attachments
by
RobertG
2 days, 2 hours ago -
advice for setting up a new windows computer
by
routtco1001
2 days, 16 hours ago -
It’s Identity Theft Day!
by
Susan Bradley
1 day, 21 hours ago -
Android 15 require minimum 32GB of storage
by
Alex5723
2 days, 21 hours ago -
Mac Mini 2018, iPhone 6s 2015 Are Now Vintage
by
Alex5723
2 days, 21 hours ago -
Hertz says hackers stole customer credit card and driver’s license data
by
Alex5723
2 days, 22 hours ago -
Firefox became sluggish
by
Rick Corbett
14 hours, 37 minutes ago -
Windows 10 Build 19045.5794 (22H2) to Release Preview Channel
by
joep517
3 days, 2 hours ago -
Windows 11 Insider Preview Build 22635.5235 (23H2) released to BETA
by
joep517
3 days, 2 hours ago -
A Funny Thing Happened on the Way to the Forum
by
bbearren
1 day, 23 hours ago -
Download speeds only 0.3Mbps after 24H2 upgrade on WiFi and Ethernet
by
John
5 hours, 3 minutes ago -
T-Mobile 5G Wireless Internet
by
WSmmi16
2 days ago -
Clock missing above calendar in Windows 10
by
WSCape Sand
2 hours, 2 minutes ago -
Formula to Calculate Q1, Q2, Q3, or Q4 of the Year?
by
WSJon5
3 days, 17 hours ago -
The time has come for AI-generated art
by
Catherine Barrett
2 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.