I found the following code which allows me to sort on the click event
of a labelbutton.
The problem occurs when I try to call the function directly from the
ClickEvent, instead of having the ClickEvent run its subroutine.
Any Ideas??
'THIS DOES NOT WORK:
= SortForm([Me],"CRNAME")
'The error is:
'The object doesn't contain the Automation object 'ME.'.
'THIS WORKS:
Private Sub lblSort1_Click()
Call SortForm(Me, "CRNAME")
End Sub
' this code is in Module1
Public Function SortForm(frm As Form, ByVal sOrderBy As String)
'Purpose: Set a form's OrderBy to the string. Reverse if already set.
'Return: True if success.
'Usage: Command button above a column 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
End If
End Function
Thanks