Full Version: Orderby
UtterAccess Discussion Forums > Microsoft® Access > Access Tables + Relationships
ebwhittaker
I am using a command button on the form against the table and set it to Me.OrderByOn=True, Me.OrderBy [lastname]
Is there any way to have it sort by either asc or desc. order ?

arnelgp
I think that was answered from previous post:

if Len(me.Orderby) > 0 Then
if Instr(Me.Orderby, "DESC") Then
Me.OrderBy = Replace(Me.OrderBy, "DESC", "")
Else
Me.OrderBy = Me.OrderBy & " DESC"
End If
Me.OrderByOn = True
Else
Me.OrderByOn=False
End If

On LoadEvent of the form:
Me.OrderBy = "[LastName]"
GroverParkGeorge
You'll have to include some conditional logic to determine the current sort order and swap it.
CODE
If Me.OrderBy = "LastName DESC" Then
    Me.OrderBy = "LastName"
Else
    Me.OrderBy =  "LastName DESC"
End If
frm.OrderByOn = True


You may refine it further--as Arnel has shown already--, but that ought to get you started
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.