3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by TheChozen
0

Try this:

With lsvwed

            Set lst = .ListItems.Add(, , (RS!Lastname))
            lst.(lsvwed.ListItems.Count).SubItems(1) = RS!Firstname
            lst.(lsvwed.ListItems.Count).SubItems(2) = RS!Middlename
            lst.(lsvwed.ListItems.Count).SubItems(3) = RS!Address
            lst.(lsvwed.ListItems.Count).SubItems(4) = RS!Age
         
        End With

Edited by abelingaw: n/a

0

sir the code that you gave didn't work. all of it turns red. I think the wrong one is in the .SubItems(). I'm not sure. :)

1

Can you check your listview control columns if it corresponds to the number of your subitems.?

I think it needs 5 columns.

Comments
Thank you for helping us fight spam!
0

although i cam elate but try this
check in ur database the column Firstname
this what is giving u the error bec the value cant be displayed
any way declaring a function and calling it make your work much easier for example u can make ur code like this
Private Sub txtsearch_KeyDown(KeyCode As Integer, Shift As Integer)
Dim str As String
Dim lst As ListItem
If KeyCode = 13 Then
Set RS = New Recordset
str = "select * from tblrecords where Lastname+' '+Firstname like '" & txtsearch.Text & "'"
RS.Open str, cn, adOpenDynamic, adLockOptimistic
lsvwed.ListItems.Clear
call loadlsvwed()
End If
End Sub

0

then u declare the public sub

public sub loadlsvwed()
on error resume next
with lsvwed
.view = lvwreport
.fullrowselect + true
.multiselect + true
.columnheaders.clear
.columnsheaders.add, , "Lastname", 1500
.columnsheaders.add, , "Firstname", 1500
.columnsheaders.add, , "Middlename", 1500
.columnsheaders.add, , "Address", 3000
.columnsheaders.add, , "Age", 500
.listitems.clear
do while not rs.EOF
set str = .listitems.add(, , rs.Fields("Lastname"), 0, 0)
.subitems(1) = rs.Fields("Firstname")
.subitems(2) = rs.Fields("Middlename")
.subitems(3) = rs.Fields("Address")
.subitems(4) = rs.Fields("Age")
rs.movenext
loop
end with
end sub

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.