ZmrAbdulla
Technical User
Hi,
Can anyone show me sample code to populate a ListView from a Query with Criteria. I am using a code but unable to populate form a query.
Code is below
I am able to populate without criteria, not with criteria. This gives me an error saying Failed to open recordset.
Thanks
Zameer Abdulla
Can anyone show me sample code to populate a ListView from a Query with Criteria. I am using a code but unable to populate form a query.
Code is below
Code:
Private Sub ListNames_Click()
Dim rs As New ADODB.Recordset
Dim colHeader As ColumnHeader
Dim lstItem As ListItem
Dim SQL As String
ListView1.ListItems.Clear
SQL = "SELECT * FROM Ledger;"
rs.Open SQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic
Me!ListView1.View = lvwReport
'Set up column headers (not using)
' With ListView1.ColumnHeaders
' .Add , , "Names", 2000
' .Add , , "Date", 1000
' .Add , , "Category", 2000
' .Add , , "Credits", 1000
' .Add , , "Debits", 1000
' End With
rs.MoveFirst
While Not rs.EOF
' Add items and subitems to list control.
Set lstItem = ListView1.ListItems.Add()
lstItem.Text = Nz(Trim(rs!Names))
lstItem.SubItems(1) = Format(Nz(Trim(rs!PymtDate)), "Medium Date")
lstItem.SubItems(2) = Nz(Trim(rs!Category))
lstItem.SubItems(3) = Format(Nz(Trim(rs!Credits), "0.00"), "Fixed")
lstItem.SubItems(4) = Format(Nz(Trim(rs!Debits), "0.00"), "Fixed")
rs.MoveNext
Wend
rs.Close
Exit Sub
End Sub
Code:
'SQL = " SELECT * FROM Ledger WHERE Names = Forms![MainForm]![ListNames];"
Thanks
Zameer Abdulla