You can't have dynamic columns in the Sort() or SortByColumns() function. You will have to use an If() or Switch() logic to figure out which column to sort by.
For example, using your formula you could change it to:
SortByColumns(
Search(
OPTrack_FormsInventoryEnhancedTables,
txtSearch.Text,
FORM_NO, REQ_DATE, COMMENT
),
Switch(
ctx_sort_column,
"crb1a_form_no",
crb1a_form_no
),
If(
ctx_sort_order,
SortOrder.Ascending,
SortOrder.Descending
)
)
However, I am not sure if you can assign columns like this.. You might have to do something like:
With(
{
_records: Search(
OPTrack_FormsInventoryEnhancedTables,
txtSearch.Text,
FORM_NO, REQ_DATE, COMMENT
),
_sortOrder: If(
ctx_sort_order,
SortOrder.Ascending,
SortOrder.Descending
)
},
Switch(
ctx_sort_column,
"crb1a_form_no",
SortByColumns(_records, crb1a_form_no, _sortOrder)
)
)
I tested the first method, and it does allow you to assign the sort column in this way, so both methods should work.