[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • Last Modified:

Sorting Continuous Forms with Label Click

I have a continuous form that I want to sort by the column (field) when the lable is clicked.  If the field is currently in DESCENDING then I want to reverse the sort when clicked.  If no sort is currently on then sort Ascending.

What is the best way to do this?

me.orderBy or DoCmd.runcommand ascmdsortascending?

0
pskeens
Asked:
pskeens
1 Solution
 
Boyd (HiTechCoach) Trimmell, Microsoft Access MVPCommented:
here is an example that does what you want:   Fancy Sort in Continuous Forms
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
The "easiest way" is to use the built-in right click menus, which include sorting and filtering. No code required.  And better yet, switch to Datasheet view forms, such that besides the right click functionality, you can drag columns next to each other and sort on multiple columns at a time.

mx
Capture1.gif
Capture1.gif
0
 
Rey Obrero (Capricorn1)Commented:
assuming the field you want to sort by is LastName and the the label is LastName_label

private sub LastName_Label_click()
if me.orderby="LastName desc" then
  me.orderby="LastName"
  else
   me.orderby="LastName desc"
end if
me.orderbyon=true

end sub
0
 
pskeensAuthor Commented:
I solved it like this:

    If OrderByOn = False Then
           Me.OrderBy = "CARRIER"
    End If
   
    If OrderByOn = True And OrderBy <> "CARRIER" Then
            Me.OrderBy = "CARRIER"
       ElseIf OrderBy = "CARRIER" Then
            Me.OrderBy = "CARRIER DESC"
       ElseIf OrderBy = "CARRIER DESC" Then
            Me.OrderBy = "CARRIER"
      End If
   
            Me.OrderByOn = True
            Me.lbl_carrier.ForeColor = RGB(255, 0, 0)

Thanks Capricorn for pointing me in the right direction!
0
 
pskeensAuthor Commented:
Pointed in the right direction but added more functionality to the solution.
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Tackle projects and never again get stuck behind a technical roadblock.
Join Now