Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid list shows last item first??? 1

Status
Not open for further replies.

Sideman

Technical User
Apr 21, 2003
41
US
Hi people,
I'm using VB6/SP5, ADODB, Access2000.
Here's a strange problem...I have a DataGrid (bound to an ADODB data control) which displays the line items from a specific invoice. It works fine displaying my data...but the items are displayed in reverse order compared to the table from which the data comes. That is...the last item is listed first, then the second last item is second, etc.
I've tried changing the table structure to no avail. I've also tried various ascending and descending sorts. It seems the data is being read from the bottom up regardless of how Access has the data stored?!?!?
Do I have to load the DataGrid through code somehow? This seems so awkward since the grid does such a nice job otherwise. Please! Help! Just point me in the right direction. (I just know there's some stupid detail I've missed)

Of all the things I've lost, I miss my mind the most!
Sideman
 
In your ADOC1's ReordSource property, set an ORDER BY:

SELECT * FROM SomeTable Order By OrderDateField Desc
 
Thanks for the reply, CCLINT.
I understand the sort options for a SQL query itself. Where my dificulty comes in is where the data is displayed in a DataGrid. I can't seem to figure out how to control the displayed order.
More detail is in order...I use a SQL query on the ADODC control, ordered by customer name, Asc, which is displayed in a combo box for user selection. Once a selection is made, a single invoice's line items are displayed in a DataGrid. Here's where the items are shown in reverse order.
Is there a property or method that controls the Asc or Desc order of the DataGrid?
Maybe I need to do a more complex query?
Any ideas???

Of all the things I've lost, I miss my mind the most!
Sideman
 
> Is there a property or method that controls the Asc or Desc order of the DataGrid?

But the DataGrid is also connected to a recordset, so this recordset, whether through an ADODC or a recordset object variable, can be sorted by adding the ORDER BY to the RecordSource or Command Text.

You are probably using a client side cursor, so you could also just use the Sort method of the Recordset:

Adodc1.Recordset.Sort = "Somefield Asc"
or
myRS.Sort = "Somefield Asc"

Please note: If the column you sort on is a Text field, and you display numeric data in it, the numeric data will be sorted as text and not in a numeric order.
 
Once again you've nailed the answer. That did it. Problem solved.
This project replaces and updates a legacy database, Foxpro 2.0 (arghhh) (converted to Access2000, of course). And I can only rework the table data just so much. There is no uniqueness in the line item entries for a given invoice...the invoice number is repeated for each line item (again arghhhhh). So, I added an autonumber field and used it for sorting as you suggested and POW!!! Success!!
Again, many thanks for your wisdom.

P.S. I'm giving you a star for being so generous and helping me get through some of my most exasperating problems.

Of all the things I've lost, I miss my mind the most!
Sideman
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top