I am STUMPED. Can someone please tell me how you would sort an access table through code. I have tried using the ORDER BY, but either I am not using it correctly, or it only works with queries, because it is not doing the job.
Thanks,
Printable View
I am STUMPED. Can someone please tell me how you would sort an access table through code. I have tried using the ORDER BY, but either I am not using it correctly, or it only works with queries, because it is not doing the job.
Thanks,
ORDER BY should work, can you give me the SQL statement?
Roger
I tried using:
Code:
cmdtext = "SELECT surl,ptitle,stitle,sbib,serror,sid FROM temptable ORDER BY serror DESC;"
'connect to the database and retrieve the code
Set adoCon = CreateObject("ADODB.Connection")
adoCon.Open gblConnectString
Set adoCmd = CreateObject("ADODB.Command")
adoCmd.ActiveConnection = adoCon
adoCmd.CommandText = cmdtext
adoCmd.Execute
That would sort your "recordset", that would not sort the Access table.
exactly, try:
serror is printed sorted in descending orderCode:cmdtext = "SELECT surl,ptitle,stitle,sbib,serror,sid FROM temptable ORDER BY serror DESC;"
dim adoRec as ADODB.Recordset
'connect to the database and retrieve the code
Set adoCon = CreateObject("ADODB.Connection")
adoCon.Open gblConnectString
Set adoCmd = CreateObject("ADODB.Command")
adoCmd.ActiveConnection = adoCon
adoCmd.CommandText = cmdtext
set adoRec = adoCmd.Execute
do while not adoRec.eof
debug.print adoRec.Fields("serror").value
adoRec.MoveNext
loop
Roger
Thanks,
Works exactly like you said.