S
steve
I found this code in another post and am trying to use it on my form. When
I run the code I get the following error: "Microsoft Access cant find the
field '|' referred to in your expression."
I have searched the function several times and can't spot the error.
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
TIA
Steve
I run the code I get the following error: "Microsoft Access cant find the
field '|' referred to in your expression."
I have searched the function several times and can't spot the error.
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
TIA
Steve