473,626 Members | 3,093 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to sort a table or a listbox based on a certain feild/column

4 New Member
Hi,
I am using a listbox to show data from a certain table, i want the user, after the listbox is filled, to be able to sort the data according to the column of his choice. I could sort the table and refresh the form, or directly sort the listbox. How can i do any of that without having to open the table?

I also tried to use a subform that shows the table, that way the user can right click on the column and sort, but the problem is that after closing the form, access asks me if i want to save changes made to the table. How can i get rid of this popup menu?

Thanks in advance for any help
Dec 17 '07 #1
3 2004
PianoMan64
374 Recognized Expert Contributor
The way to get around it is like this.

You create button on the form that will allow the use to sort by whichever button they push.

When the Click event happens for each of the buttons, you simply pass a SQL String to the Listcontrol under the property of .RowSource = sqlStr. Then simply do a me.listcontroln ame.requery and me.repaint and that's it.

If you would like that coded out, let me know.


Hope that helps,

Joe P.
Jan 5 '08 #2
missinglinq
3,532 Recognized Expert Specialist
The fact of the matter is that you're having trouble doing this because you're trying to use an Access control for something that it's not designed to do!

Listboxes
are intended to be used to select data that will then, either directly or indirectly, be used to add data to a record! They are not intended to be used to simply display data! This is why Access doesn't provide a way to sort them by columns!

This is akin to buying an Ferrari and wondering why you can't plow your garden with it!


Linq ;0)>
Jan 5 '08 #3
RamiH
4 New Member
The way to get around it is like this.

You create button on the form that will allow the use to sort by whichever button they push.

When the Click event happens for each of the buttons, you simply pass a SQL String to the Listcontrol under the property of .RowSource = sqlStr. Then simply do a me.listcontroln ame.requery and me.repaint and that's it.

If you would like that coded out, let me know.


Hope that helps,

Joe P.

Hi Joe,
thanks for your help i appreciate it a lot.
well i did as u said:
listcontrolname .rowsource = sqlStr
me.listcontroln ame.requery
me.repaint

but it only empties the list! any ideas?

thanks again for your help
Jan 28 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
4810
by: bissatch | last post by:
Hi, I am about to create a table, where the values are taken from an XML file, where each column header you can click and it will sort the table rows at the client side. I have got to the following stage: //first the xml file loading part
1
5013
by: Alvey Sidecast | last post by:
This is probably embarrassingly simple, but I've been trawling through this ng for hours now and my brain hurts. I've got an unbound multi-column listbox (multi-select=none) whose rowsource is a query based on a combobox selection. After the selection is made from the combobox the listbox may, or may not, have records in it. If it doesn't, no problems, I've got; If Me.lbxContacts.ItemsSelected.Count = 0 Then
0
2294
by: Ray | last post by:
Folks, I have just created a simple procedure that does the following: Determines the width of the columns of a listbox. Places a button of the correct size above each column as the form opens. Sorts by that column when you click the button. Automatically toggles between ASC and DESC sort sequence. To implement it on a new form, you simply copy the buttons from my
2
6065
by: Alan Lane | last post by:
Hello world: I'm using Access 2003. I have 2 listboxes. One is a single column. The other has two columns. I can use Dev Ashish's code (thanks Dev!) from the Access MVP Website to accumulate the values from the bound column of a MultiSelect listbox, so that I can include them in a SQL query that will then be the recordsource for a report. This gives me 2 of the 3 values I need to put into the SQL query. However, I can't get the non...
4
2265
by: Just Me | last post by:
I populate a ListBox with Objects (not Strings) that has a String field (which is displayed) and an Integer field (which is not displayed). I need to have the displayed items in the Listbox sorted. But sorted by the Integer field not the displayed String. Is there some way I can do that (in much the way a ListView can be sorted by any column) Thanks
3
2070
by: Vic Spainhower | last post by:
Hello, I have an HTML table that is being constructed from a MySQL table and displays a form that includes a check box on 1 of the fields on the form for each record. I have included in this PHP program a javascript routine called sorttable.js which is something I found on the internet for sorting tables and works quite well. The HTML table includes a check box on each record so the user can select certain records for passing to the...
5
8152
by: muskie | last post by:
I've looked through as many posts about this as possible, but all end with no resolution. I simply need records from a table in random order, and I will be calling this recordset in a SQL statement from ASP. I've tried the following but it does not produce random order: SELECT * FROM Table1 ORDER BY Rnd(TableID) ASC; where TableID is an autonumber field. I've seen references to Randomize, but how do you use Access's
6
3377
by: BerkshireGuy | last post by:
On an unbound form, I have a combobox called 'cboproducttype' and a text box called 'txtamountappliedfor'. I have an Add button that I would like the user to be able to hit once a product and amount applied for has been entered. This should populate an unbound listbox to display their selections. A user can select one or more sets of product types and the amount applied for. They should also have the functionality to remove a 'set' if...
1
1781
by: troy_lee | last post by:
I have a list box based on a query. I set the row source in vba with a dynamic string. I have a combo box at the top of the form that selects a unit number (formatted as text). This unit number is the PK for the main table. The listbox referenced above is used to create a rework report for the selected unit. What I need to do is grab the unit number from the combo box, (which we designate as - I know it's screwy and not right- not my
0
8259
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8192
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8637
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8358
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7188
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5571
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.