By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,101 Members | 1,463 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,101 IT Pros & Developers. It's quick & easy.

Sorting issue when filtering

100+
P: 161
Expand|Select|Wrap|Line Numbers
  1. Private Sub ApplyFilter_Click()
  2.  
  3. On Error GoTo ErrorHandler
  4.  
  5.     Dim strFilter As String
  6.  
  7.     strFilter = ""
  8.     If Not IsNull(Me.cmbSearchDate) Then
  9.         strFilter = _
  10.             " AND [LineDate] = " & _
  11.                 "#" & Format(Me.cmbSearchDate, "mm-dd-yyyy") & "#"
  12.     End If
  13.  
  14.     If Not IsNull(Me.CmbLineSearch) Then
  15.         strFilter = _
  16.             strFilter & _
  17.                 " AND [LineNo] = " & _
  18.                     Me.CmbLineSearch
  19.     End If
  20.  
  21.     If Not IsNull(Me.cmbShiftSearch) Then
  22.         strFilter = _
  23.             strFilter & _
  24.                 " AND [Shift] = " & _
  25.                      Me.cmbShiftSearch
  26.     End If
  27.  
  28.     Me.OrderByOn = True
  29.     Me.OrderBy = "[LineNO]"
  30.  
  31.     Debug.Print Mid(strFilter, 6)
  32.  
  33.     Debug.Print Me.OrderBy = "[LineNO]"
  34.  
  35.     With Me.Form
  36.         .Filter = Mid(strFilter, 6)
  37.         .FilterOn = (Not strFilter = "")
  38.  
  39.     End With
  40.  
  41. ErrorHandler:
  42.    ' Insert code to handle the error here
  43.    Resume Next
  44.  
  45. End Sub
It doesn't through any kind of error but it doesn't sort the field I want. It Seems to sort by the forms PK.

Is there something I have entered wrong? Do I need to take the sort out of the query? Do I need to set focus to that field first?
4 Weeks Ago #1
Share this Question
Share on Google+
1 Reply


100+
P: 161
I figured it out, it should have been:

Expand|Select|Wrap|Line Numbers
  1.  Me.OrderByOn = True
  2.     Me.OrderBy = "[LineNOID]"
4 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.