Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to sort a table...

nearlycanadiannearlycanadian Posts: 14Member
My question is this:
I have a VBA script that (among other things) reads information from a table and stores it in an array (the size of the table). What I would like to know is this: Is it possible to sort it (using an SQL statement) by more than one column in the table? Let's say my statement looks like this...

strSQL = "SELECT * FROM testdb_main ORDER BY Name, Date"
Set rstTest = dbsTest.OpenRecordset(strSQL)

If I do this, it will only order it by name, and the dates are all over the place.

If anyone could help me, I would truly appreciate it. Thank you.

Comments

  • matthewmmatthewm Posts: 5Member
    : My question is this:
    : I have a VBA script that (among other things) reads information from a table and stores it in an array (the size of the table). What I would like to know is this: Is it possible to sort it (using an SQL statement) by more than one column in the table? Let's say my statement looks like this...
    :
    : strSQL = "SELECT * FROM testdb_main ORDER BY Name, Date"
    : Set rstTest = dbsTest.OpenRecordset(strSQL)
    :
    : If I do this, it will only order it by name, and the dates are all over the place.
    :
    : If anyone could help me, I would truly appreciate it. Thank you.
    :

    suggestion...

    strSQL = "SELECT * FROM testdb_main ORDER BY testdb_main.Name, testdb_main.Date

    ...posit... the SQL interpreter is interpreting Date as the date function Date() not as the column name Date in table testdb_main. So force it by explicitly naming the table in the ORDER clause.

    it may be a daft idea (don't have the version to hand to try out) but Microsoft products are pretty darn stupid...
    message me back if it works!





Sign In or Register to comment.