954,551 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ADO Sort

I currently have the following code

Data1.Recordset.Sort = ("Barcode ID DEC")


In which i want to sort all the Barcode ID records in Descending order. The barcodes have leading zero's which i think may be the problem. For example 00000055. Any suggestions?

gowans07
Light Poster
48 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

for a start shouldn't it be DESC not DEC and

if you are talking to MS SQL Barcode ID cannot have a space in it, eg BarcodeId
if you are talking to MSAccess then it needs to be inclosed in square brackets [Barcode ID]

ChrisPadgham
Posting Pro in Training
413 posts since Sep 2009
Reputation Points: 102
Solved Threads: 78
 

Thanks for the reply, so Data1.recordset.sort [Barcode ID DESC] or Data1.recordset.sort = [Barcode ID DESC]

gowans07
Light Poster
48 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 
Data1.Recordset.Sort ["Barcode ID DESC"]
Do Until Data1.Recordset.EOF
    HE = Data1.Recordset("Barcode ID")
    MsgBox HE
    Data1.Recordset.MoveNext
Loop


I've tried multiple variations of the first line, what is wrong, if i have [ ] its says Compile error, external name not defined.

gowans07
Light Poster
48 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

the square brackets should be around the fieldname

Data1.Recordset.Sort ("[Barcode ID] DESC")
Do Until Data1.Recordset.EOF    
   HE = Data1.Recordset("[Barcode ID]")    
   MsgBox HE    
   Data1.Recordset.MoveNext
Loop
ChrisPadgham
Posting Pro in Training
413 posts since Sep 2009
Reputation Points: 102
Solved Threads: 78
 

Invalid Use of property on the first line.

gowans07
Light Poster
48 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

try this


Data1.Recordset.Sort "[Barcode ID] DESC"

ChrisPadgham
Posting Pro in Training
413 posts since Sep 2009
Reputation Points: 102
Solved Threads: 78
 

Same error again, thanks for the help i'll just hardcode some other stuff in instead.

gowans07
Light Poster
48 posts since Sep 2011
Reputation Points: 10
Solved Threads: 1
 

.sort is not support by all ADO, perhaps it is simpler to put the sort in the SQL

stSQL = "SELECT [Barcode ID] FROM Barcode ORDER BY [Barcode ID]"

ChrisPadgham
Posting Pro in Training
413 posts since Sep 2009
Reputation Points: 102
Solved Threads: 78
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You