General discussion

Locked

sort form data using a combo box

By ka75 ·
I have a form connected to an sql query and showing data. the data can be changed through the form.

I want to add a combo box that will contain the columns headers. When choosing (clicking) a header name in the combo box I want the data in the form to be sorted by the value chosen.

I guess a VB code is needed but I would not know where to start.

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by R. A. Caluste In reply to sort form data using a co ...

Try this approach:

In your SQL select query statement: "Select * from tablename where field = criteria order by " & combo1.list(combo1.listindex) & " ASC"

Where combo1 contains your pre-defined column headers. Do a re-query at the combo1_click event and re-display the contents of the form.

Another approach is the use of the Sort property in your recordset. Here, i'm assuming you are using ADO (Activex Data Objects) in accessing your data.

rs.Sort = combo1.list(combo1.listindex)

however, you must consider the following:
1. recordset must use a client-side cursor.
2. you cannot use a recordset with a field named ASC or DESC.
3. you cannot apply a filter (using the Filter property) when you want to sort it using the sort property. ADO does not sort as long as a filter is applied.

Insert this in the combo1_click event; re-sort and re-display data in form.

hope this helps.

Allan

Back to Software Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums