You could write (assuming that ResultDate is a Date type column in your table)
query = "SELECT TOP 1 ResultDate FROM ASPECTRESULTS WHERE ..... " & _
"ORDER BY RESULTDATE DESC"
This will return the highest date in the ResultDate column
Said that, you should really study how a parameterized query works and why you should ALWAYS use parameters instead of string concatenations
EDIT
From your comment above (ResultDate is a Char(10)), then getting this field correctly ordered is real pain, in particular if you store the date as dd/MM/yyyy
. With this format in a char ordering the value '11/01/2013'
follows the value '01/01/2014'
. This is one of the many reasons to ALWAYS store datetime values in datetime fields. The database will know how to correctly handle a date without considering how is represented by a string.
You have two options to overcome from this hurdle.
- Change the datatype of the field ResultDate to a DateTime field (recommended)
- Store your values using a 'sortable' char format (yyyy/MM/dd with
always two digits for months and days (not recommended)