beckwiga
Programmer
- Mar 30, 2005
- 70
Want to sort my ListView when user clicks a column heading. I have the following code which I believe is correct. Getting the following error, anyone know what this means? This is all VBA by the way.
Here is my code for the listview sort:
Private Sub ListView0_ColumnClick()
With ListView0
Static iLast As Integer, iCur As Integer
.Sorted = True
iCur = ColumnHeader.Index - 1
If iCur = iLast Then .SortOrder = IIf(.SortOrder = 1, 0, 1)
.SortKey = iCur
iLast = iCur
End With
Here's my code for the Listview on form open code. This part works fine. This is pretty much all the code I have so far for the entire form.
Private Sub Form_Open(Cancel As Integer)
Dim rs As DAO.Recordset
Dim db As Database
Dim iCount As Integer
Dim LIX As ListItem
ListView0.ListItems.Clear
ListView0.ColumnHeaders.Clear
Set db = CurrentDb
Set rs = db.OpenRecordset("Select * From ListView0")
For iCount = 0 To rs.Fields.Count - 1
ListView0.ColumnHeaders.Add , , rs.Fields(iCount).Name
Next
Do While Not rs.EOF
For iCount = 0 To rs.Fields.Count - 1
If iCount = 0 Then
Set LIX = ListView0.ListItems.Add
LIX.Text = rs.Fields(iCount).Value & ""
Else
LIX.SubItems(iCount) = rs.Fields(iCount).Value & ""
End If
Next
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub
Here is my code for the listview sort:
Private Sub ListView0_ColumnClick()
With ListView0
Static iLast As Integer, iCur As Integer
.Sorted = True
iCur = ColumnHeader.Index - 1
If iCur = iLast Then .SortOrder = IIf(.SortOrder = 1, 0, 1)
.SortKey = iCur
iLast = iCur
End With
Here's my code for the Listview on form open code. This part works fine. This is pretty much all the code I have so far for the entire form.
Private Sub Form_Open(Cancel As Integer)
Dim rs As DAO.Recordset
Dim db As Database
Dim iCount As Integer
Dim LIX As ListItem
ListView0.ListItems.Clear
ListView0.ColumnHeaders.Clear
Set db = CurrentDb
Set rs = db.OpenRecordset("Select * From ListView0")
For iCount = 0 To rs.Fields.Count - 1
ListView0.ColumnHeaders.Add , , rs.Fields(iCount).Name
Next
Do While Not rs.EOF
For iCount = 0 To rs.Fields.Count - 1
If iCount = 0 Then
Set LIX = ListView0.ListItems.Add
LIX.Text = rs.Fields(iCount).Value & ""
Else
LIX.SubItems(iCount) = rs.Fields(iCount).Value & ""
End If
Next
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
End Sub