Sort Field in subforms results

oxicottin

Learning by pecking away....
Local time
Today, 08:40
Joined
Jun 26, 2007
Messages
889
Hello, I have a search form frm_VWI with subform sfrm_VWI and in the subforms header I want to add a command button to sort a field [DateReviewed]. I want to start out with A-Z for the buttons caption and once pressed it sorts the [DateReviewed] and changes the buttons caption to Z-A and when pressed it sorts the field, back and forth with the button. How is this done? I tried but it asked for a parameter value and showed the first date in the first record.

Code:
Private Sub cmdAccDateReviewed_Click()

If Me.OrderBy = [DateReviewed] Then
      Me.OrderBy = "[DateReviewed] DESC"
Else
     Me.OrderBy = [DateReviewed]
End If
Me.OrderByOn = True
End Sub
 
Hi. Try enclosing the field name in quotes because the OrderBy property contains a String value.
 
That worked, Thanks!

Code:
If Me.OrderBy ="[DateReviewed]" Then
      Me.OrderBy = "[DateReviewed] DESC"
      Me.cmdAccDateReviewed.Caption = "Z - A"
Else
     Me.OrderBy = "[DateReviewed]"
     Me.cmdAccDateReviewed.Caption = "A - Z"
End If
Me.OrderByOn = True
 
That worked, Thanks!

Code:
If Me.OrderBy ="[DateReviewed]" Then
      Me.OrderBy = "[DateReviewed] DESC"
      Me.cmdAccDateReviewed.Caption = "Z - A"
Else
     Me.OrderBy = "[DateReviewed]"
     Me.cmdAccDateReviewed.Caption = "A - Z"
End If
Me.OrderByOn = True
Congratulations! Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Back
Top Bottom