Sorting

  • Thread starter Thread starter Vina
  • Start date Start date
V

Vina

I have a continuos form and was wondering how I can add a
feature that they can click on the label and it will be
sorted accordingly. is there a function that is built in
Access to do this.

Any info is appreciated.

Thanks
Vina
 
Vina said:
I have a continuos form and was wondering how I can add a
feature that they can click on the label and it will be
sorted accordingly. is there a function that is built in
Access to do this.

Any info is appreciated.

There's a builtin property to control the form's sort sequence, but
there's nothing builtin to make this happen when you click a particular
label. For that, you have to write a little code. I have a form set up
the way you describe, in which I use this function:

'---- start of function code -----
Function SetSortOrder(FieldName As String)

' If the form is already ordered by <FieldName>,
' just reverse the sort order.
If Me.OrderBy Like FieldName & "*" _
And Me.OrderByOn = True _
Then
If Split(Me.OrderBy & " ASC", " ", , vbTextCompare)(1) = "ASC" _
Then
Me.OrderBy = FieldName & " DESC"
Else
Me.OrderBy = FieldName & " ASC"
End If
Else
' Not already ordered by this field, so
' sort ascending on it.
Me.OrderBy = FieldName & " ASC"
End If

Me.OrderByOn = True

Me.Recalc

End Function
'---- end of function code -----

With this function defined in the General section of the form's module,
I can set each label's OnClick property to a function expression like
this:

=SetSortOrder("ProjectName")

or

=SetSortOrder("ClientName")

That is, the function expression for each label's OnClick property calls
the function and passes the name of the field to be sorted on.
 
Thanks this help a lot
-----Original Message-----


There's a builtin property to control the form's sort sequence, but
there's nothing builtin to make this happen when you click a particular
label. For that, you have to write a little code. I have a form set up
the way you describe, in which I use this function:

'---- start of function code -----
Function SetSortOrder(FieldName As String)

' If the form is already ordered by <FieldName>,
' just reverse the sort order.
If Me.OrderBy Like FieldName & "*" _
And Me.OrderByOn = True _
Then
If Split(Me.OrderBy & " ASC", " ", , vbTextCompare)(1) = "ASC" _
Then
Me.OrderBy = FieldName & " DESC"
Else
Me.OrderBy = FieldName & " ASC"
End If
Else
' Not already ordered by this field, so
' sort ascending on it.
Me.OrderBy = FieldName & " ASC"
End If

Me.OrderByOn = True

Me.Recalc

End Function
'---- end of function code -----

With this function defined in the General section of the form's module,
I can set each label's OnClick property to a function expression like
this:

=SetSortOrder("ProjectName")

or

=SetSortOrder("ClientName")

That is, the function expression for each label's OnClick property calls
the function and passes the name of the field to be sorted on.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)


.
 
Back
Top