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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting by date 1

Status
Not open for further replies.

TMD

Programmer
Jan 19, 2002
24
GB
Can anybody tell me how i can sort records by date in VB6.

I have made a Maintenance program using vb, which gets the data from a relational database in access2000. There can be many repairs to each serial number

when i add new repair details to a serial number, they can be scrolled through, but I would like to scroll through them in date order, so that the first record is the earliest and last record is latest.

Thanx in advance.
 
In your SQL statement just use :
Order by [datefield]
where [datefield] is the name of the datefield ion your data.

If you're using a query from Access, just go to design view and click in the Sort box under your field name and select 'ascending'


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
They already are is date order in access, but I've just tested it by adding new entries at varied dates, when access is refreshed it puts them in chronological order, but when i go back into my vbp which uses the database, they scroll in order of entry, not date, i was wondering if there was some code that i could put in vb to set the order.
 
How are you getting the data into VB? If you're using a query of some sort, try my suggestion above - otherwise let us know what you're using.


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Probably a DataGrid.
After adding the record, re-sort the records using the ADO Sort method:

Adodc1.Recordset.Sort = "myDateField"

you might want to assign the recordset bookmark to a variant variable, then do the sort, and then set the recordset bookmark to the bookmark held in the variable, so the cursor remains at that same record.
 
i was originally just connecting to the repair table, but I've just one back into access and created a query of the repair table to show everything, and sort by ascending date.

Back in my program and new entries are placed in order,

Thanx for the help johnwm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top