Hi!!
I have a listbox on a single form that is not cooperating. I searched through the threads and found some info but can't make it work.
Using Access 2010 in 2007 mode. I am only working with the Case "lblPartNumber", the rest is waiting for this solution. I had it all set up and working with a continuous form but now I need multiselect so I am converting to a listbox.
It goes through the motions but the records in the listbox are not getting sorted. Can anybody see my mistake?
Thanks for looking.
Joel
I have a listbox on a single form that is not cooperating. I searched through the threads and found some info but can't make it work.
Using Access 2010 in 2007 mode. I am only working with the Case "lblPartNumber", the rest is waiting for this solution. I had it all set up and working with a continuous form but now I need multiselect so I am converting to a listbox.
Code:
Private Sub SortDetail(SortField)
'from the label click events of Part Number, Description, Route and Station
'keep sort order from the Description and or the Part Number field
Dim rstemp As Recordset
Dim strNewSortOrder As String
Select Case SortField
Case "lblPartNumber"
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "DESC", vbTextCompare) = 0 Or Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "" Then
Set rstemp = Me.lbxPartRouteAssignmentAdd.Recordset.Clone
rstemp.Sort = "PartNumber DESC"
Else
Set rstemp = Me.lbxPartRouteAssignmentAdd.Recordset.Clone
rstemp.Sort = "PartNumber"
End If
Case "lblRoute"
If Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "" Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "Route"
''' Me.lbxPartRouteAssignmentAdd.Recordset.sortByOn = True
Exit Sub
End If
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Description", vbTextCompare) <> 0 Then
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Route", vbTextCompare) <> 0 Then
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Description DESC", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Description] DESC", vbTextCompare) <> 0 Then
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Route DESC", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Route] DESC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Route] ASC, [Description] DESC"
ElseIf InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Route", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Route] ASC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Route] DESC, [Description] DESC"
End If
ElseIf InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Description", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Description] ASC", vbTextCompare) <> 0 Then
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Route DESC", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Route] DESC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Route] ASC, [Description] ASC"
ElseIf InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Route", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Route] ASC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Route] DESC, [Description] ASC"
End If
End If
Else
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Description DESC", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Description] DESC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Route] ASC, [Description] DESC"
Else
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Route] ASC, [Description] ASC"
End If
End If
ElseIf InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Route", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Route] ASC", vbTextCompare) <> 0 Then
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Route DESC", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Route] DESC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Route] ASC"
Else
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Route] DESC"
End If
End If
Case "lblStation"
If Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "" Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "Station"
''' Me.lbxPartRouteAssignmentAdd.Recordset.SortOn = True
Exit Sub
End If
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Description", vbTextCompare) <> 0 Then
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Station", vbTextCompare) <> 0 Then
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Description DESC", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Description] DESC", vbTextCompare) <> 0 Then
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Station DESC", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Station] DESC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Station] ASC, [Description] DESC"
ElseIf InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Station", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Station] ASC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Station] DESC, [Description] DESC"
End If
ElseIf InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Description", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Description] ASC", vbTextCompare) <> 0 Then
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Station DESC", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Station] DESC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Station] ASC, [Description] ASC"
ElseIf InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Station", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Station] ASC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Station] DESC, [Description] ASC"
End If
End If
Else
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Description DESC", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Description] DESC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Station] ASC, [Description] DESC"
Else
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Station] ASC, [Description] ASC"
End If
End If
ElseIf InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Station", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Station] ASC", vbTextCompare) <> 0 Then
If InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "Station DESC", vbTextCompare) <> 0 Or InStr(1, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "[Station] DESC", vbTextCompare) <> 0 Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Station] ASC"
Else
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "[Station] DESC"
End If
End If
Case "lblDescription"
'start Instr at position 5 because field name contains string we're seeking
'Access is not case specific
If InStr(5, Me.lbxPartRouteAssignmentAdd.Recordset.Sort, "DESC", vbTextCompare) = 0 Or Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "" Then
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "Description DESC"
Else
Me.lbxPartRouteAssignmentAdd.Recordset.Sort = "Description"
End If
Case Else
Exit Sub
End Select
''' Me.lbxPartRouteAssignmentAdd.Requery
''' Set rstemp = rstemp.OpenRecordset
Set Me.lbxPartRouteAssignmentAdd.Recordset = rstemp
Me.lbxPartRouteAssignmentAdd.Requery
Me.Refresh
End Sub
It goes through the motions but the records in the listbox are not getting sorted. Can anybody see my mistake?
Thanks for looking.
Joel