Orderby function with reverse sort

S

Sean Grieco

Is there a way to use the orderby function but be able to choose whether you
sort ascending or descending? Right now I have made a button on a form that
changes what fields are being sorted but I would like it if they hit the
button a second time it will reverses the sort. Thanks!
 
G

Guest

Hi,
To get the order to reverse, type DESC after the field name.
eg:
Me.OrderBy = "field1 DESC"
Regards,

Lee
 
F

fredg

Is there a way to use the orderby function but be able to choose whether you
sort ascending or descending? Right now I have made a button on a form that
changes what fields are being sorted but I would like it if they hit the
button a second time it will reverses the sort. Thanks!

Is there a reason why you don't use the built in sort tool buttons:
A-Z or Z-A?

If Right(Me.OrderBy, 5) = " DESC" Then
Me.OrderBy = Left(Me.OrderBy, Len(Me.OrderBy) - 5)
Else
Me.OrderBy = Me.OrderBy & " DESC"
End If
 
S

Sean Grieco

Thanks a lot, that worked great!

Baby Face Lee said:
Hi,
To get the order to reverse, type DESC after the field name.
eg:
Me.OrderBy = "field1 DESC"
Regards,

Lee
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top