Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternating sort order in a form

Status
Not open for further replies.

RemyS

Technical User
Jul 3, 2001
100
GB
I remember seeing once a simple method which could change the way the records in a form were sorted, but I can't find it again.

The present alternatives I have are to assign different SQL to the Me.RecordSource property, but that can get messy when I use other SQL assignments.

I've also looked at the OrderBy property, but I haven't been able to set it.
Me.OrderBy causes a compile error: Invalid use of property. The help files don't give any examples as to how to set this in code.

Could anyone help, or know of that third illusive method which is really what I'm after? 101 ways to do it with VB, 99 more things to learn.
 
Dunno if this would be easy or not, but how about DoCmd.ApplyFilter ??

Just a suggestion, may be wide of the mark!

Pete
 
..and if you're curious, here's the technique

1) continuous form.
2) Use a click-able obect as the column heading.
3) in objects CLICK event, send the name of the field to this standard function:

Function SortForm(frm As Form, ByVal sOrderBy As String) As Boolean
'Purpose: Set a form's OrderBy to the string. Reverse if already set.
'Return: True if success.
'Usage: click-able object as a column heading in a continuous form:
' Call SortForm(Me, "MyField")

If Len(sOrderBy) > 0 Then
' Reverse the order if already sorted this way.
If frm.OrderByOn And (frm.OrderBy = sOrderBy) Then
sOrderBy = sOrderBy & " DESC"
End If
frm.OrderBy = sOrderBy
frm.OrderByOn = True
' Succeeded.
SortForm = True
End If
End Function

How many of you believe in telekinesis? Raise my hand...
Another free Access forum:
More Access stuff at
 
BRILLIANT!
It worked, and I now understand how to use the .Orderby property; no where in the help files did it mention using an '=', and I guess I must have been a little sleepy this morning to have not tried it myself.

Thanks.

P.S. I'm very relieved, though slightly puzzled, that no animals were harmed for the sake of your web "ramblings."
P.P.S. I really wasn't trying to make you spill your coffee. How was I to know you'd be holding it at the time. I'm telekinetic, not telepathic. sorry about that.:) 101 ways to do it with VB, 99 more things to learn.
 
I recently passed a house whose occupant advertised herself as a "Psychic Reader" - it had suffered fire damage, which I wondered about, considering the powers of the owner...

Glad it worked out for you.

Jim


How many of you believe in telekinesis? Raise my hand...
Another free Access forum:
More Access stuff at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top