S
Secret Squirrel
I have on my main form some combo boxes that allow users to filter records on
my subform. The command button that fires this sort has this code behind it:
Dim sSql As String
Dim sCriteria As String
sCriteria = "WHERE 1=1 "
If Me![txtRegion] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.Region
Like """ & txtRegion & "*"""
End If
If Me![txtMarket] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.Market Like
""" & txtMarket & "*"""
End If
If Me![txtState] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.State
Like """ & txtState & "*"""
End If
If Me![txtSource] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.Source
Like """ & txtSource & "*"""
End If
If Me![txtSalesRep] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.SalesRep
Like """ & txtSalesRep & "*"""
End If
If Nz(DCount("*", "qrySearchCriteriaSub", right(sCriteria,
Len(sCriteria) - 14)), 0) > 0 Then
sSql = "SELECT DISTINCT [RECORDID],
[COMPANYNAME],[CITY],[STATE],[ZIPCODE],[PHONENO], [CONTACTNAME1], [WEBSITE],
[PRIORITYCODE], [SOURCE] from qrySearchCriteriaSub " & sCriteria
Forms![frmSearchCriteriaMain]![frmSearchCriteriaSub].Form.RecordSource = sSql
Forms![frmSearchCriteriaMain]![frmSearchCriteriaSub].Form.Requery
Else
MsgBox "The search failed find any records" & vbCr & vbCr & _
"that matches your search criteria?", vbOKOnly + vbQuestion, "Search
Record"
txtSource = Null
txtSalesRep = Null
txtMarket = Null
txtRegion = Null
txtState = Null
End If
The problem I'm having is I can't sort the records by company name. In the
query I have the company name set to sort ascending but for some reason when
they fire the filter it won't sort by the company name. I'm assuming that the
problem must lie in this code because when I test the query out alone it
sorts fine. Can anyone maybe shed some light on why it won't carry the sort
from the query to the form?
my subform. The command button that fires this sort has this code behind it:
Dim sSql As String
Dim sCriteria As String
sCriteria = "WHERE 1=1 "
If Me![txtRegion] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.Region
Like """ & txtRegion & "*"""
End If
If Me![txtMarket] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.Market Like
""" & txtMarket & "*"""
End If
If Me![txtState] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.State
Like """ & txtState & "*"""
End If
If Me![txtSource] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.Source
Like """ & txtSource & "*"""
End If
If Me![txtSalesRep] <> "" Then
sCriteria = sCriteria & " AND qrySearchCriteriaSub.SalesRep
Like """ & txtSalesRep & "*"""
End If
If Nz(DCount("*", "qrySearchCriteriaSub", right(sCriteria,
Len(sCriteria) - 14)), 0) > 0 Then
sSql = "SELECT DISTINCT [RECORDID],
[COMPANYNAME],[CITY],[STATE],[ZIPCODE],[PHONENO], [CONTACTNAME1], [WEBSITE],
[PRIORITYCODE], [SOURCE] from qrySearchCriteriaSub " & sCriteria
Forms![frmSearchCriteriaMain]![frmSearchCriteriaSub].Form.RecordSource = sSql
Forms![frmSearchCriteriaMain]![frmSearchCriteriaSub].Form.Requery
Else
MsgBox "The search failed find any records" & vbCr & vbCr & _
"that matches your search criteria?", vbOKOnly + vbQuestion, "Search
Record"
txtSource = Null
txtSalesRep = Null
txtMarket = Null
txtRegion = Null
txtState = Null
End If
The problem I'm having is I can't sort the records by company name. In the
query I have the company name set to sort ascending but for some reason when
they fire the filter it won't sort by the company name. I'm assuming that the
problem must lie in this code because when I test the query out alone it
sorts fine. Can anyone maybe shed some light on why it won't carry the sort
from the query to the form?