I got this code written by Allen Brown and it works great. But the only concern I have is that when I click the command button once (Call SortForm(Me, "[Priority]"), it sorts my values (priority expressed in numbers) in descending order fine but the ascending order shows blank rows first followed by correct ascending order. Is there something I can do to tweak this to drop blank rows at the end?
Function SortForm(frm As Form, ByVal sOrderBy As String) As Boolean
On Error GoTo Err_SortForm 'Provided by Allen Browne
'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")
Dim sForm As String ' Form name (for error handler).
sForm = frm.Name
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
Exit_SortForm:
Exit Function
Err_SortForm: ' Label to jump to on error.
MsgBox err.Number & err.Description ' Place error handling here.
'Call LogError(Err.Number, Err.Description, conMod & ".SortForm()","Form'= " & sForm & "; OrderBy = " & sOrderBy)
Resume Exit_SortForm
End Function
Function SortForm(frm As Form, ByVal sOrderBy As String) As Boolean
On Error GoTo Err_SortForm 'Provided by Allen Browne
'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")
Dim sForm As String ' Form name (for error handler).
sForm = frm.Name
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
Exit_SortForm:
Exit Function
Err_SortForm: ' Label to jump to on error.
MsgBox err.Number & err.Description ' Place error handling here.
'Call LogError(Err.Number, Err.Description, conMod & ".SortForm()","Form'= " & sForm & "; OrderBy = " & sOrderBy)
Resume Exit_SortForm
End Function