This part
Code:
strSQL = "SELECT DISTINCTROW N_T_BatchFinalSpecs.* FROM N_T_BatchFinalSpecs " & _
"WHERE " & strSQL & _
Doesn't look right. I see this being interpreted as
SELECT DISTINCTROW N_T_BatchFinalSpecs.* FROM N_T_BatchFinalSpecs
WHERE SELECT DISTINCTROW N_T_BatchFinalSpecs.* FROM N_T_BatchFinalSpecs...
since you're adding the already defined value held by strSql.
Suggest you break the sql construct into as many parts as there are different:
strSelPart = "SELECT... WHERE "
strWherePart "criteria here "
If condition1 Then strSortPart = "ORDER BY one field"
Else
strSortPart = "ORDER BY other field"
strSql = strSelpart & strWherePart & strSortPart
Watch that you construct the parts properly, ensuring the concatenation has spaces where they should be.
BTW, you shouldn't need the repaint.
The more we hear silence, the more we begin to think about our value in this universe.
Paraphrase of Professor Brian Cox.