Hello everyone! :) I'm sorry I'm new to this stuff. So I'm trying to create a simple system information and I am attempting to populate a listview control and I get a Run-time error '380': Invalid property value. I hope you can help me and I hope it made sense.

Here's the line to regenerates the error:

.SubItems(3) = rs!Owner_Address

Here's my entire code:

Option Explicit
Dim lst As ListItem
Dim lst1 As ListItem
Dim OwnerID As Long
Dim warning As String
Dim countertitle As Integer
Dim title As String
Dim titledance As String

Public Sub FillListView()
Set lst = lvStudentRecord.ListItems.Add(, , txtID.Text)
    With lst
        .SubItems(1) = txtID.Text
        .SubItems(2) = txtname.Text
        .SubItems(3) = txtadd.Text
    End With
End Sub

Private Sub cmdaddstudent_Click()
If txtname.Text = "" Or txtID.Text = "" Or txtadd.Text = "" Then
        MsgBox "Please fill all the fields..", vbExclamation, ""
    Exit Sub
Else
Connection
sql = "tbl_Owner"
Set rs = New ADODB.Recordset
rs.Open sql, Conn, adOpenDynamic, adLockOptimistic
With rs
    .AddNew
        !Owner_ID = txtID.Text
        !Owner_Name = txtname.Text
        !Owner_Address = txtadd.Text
    .Update
End With
End If

MsgBox "New student record successfully saved..", vbInformation, "Success"
Call FillListView

    txtname.Text = ""
    txtID.Text = ""
    txtadd.Text = ""
   
Set rs = New ADODB.Recordset
sql = "SELECT Owner_ID FROM tbl_Owner"
rs.Open sql, Conn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
    With rs
        .MoveLast
            txtID.Text = !Owner_ID + Val(1)
        .Close
    End With
End If

lvStudentInfo.ListItems.Clear
    Call GetStudentRecord
End Sub

Private Sub cmdcancel_Click()
    Unload Me
End Sub

Private Sub cmdclose_Click()
    Unload Me
End Sub

Private Sub cmddeleterecord_Click()
warning = MsgBox("Are you sure you want to delete this record..", vbQuestion + vbYesNo, "")
If warning = vbYes Then
Connection
sql = "SELECT * FROM tbl_Owner WHERE clng(Owner_ID)='" & OwnerID & "'"
Set rs = New ADODB.Recordset
rs.Open sql, Conn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
    With rs
        .Delete
    End With
        lvStudentInfo.ListItems.Clear
            Call GetStudentRecord
        MsgBox "Record successfully deleted..", vbInformation, "Success"
    End If
End If

End Sub

Private Sub cmdeditrecord_Click()
With Form2
    .txtID.Text = lvStudentInfo.SelectedItem.SubItems(1)
    .txtname.Text = lvStudentInfo.SelectedItem.SubItems(2)
    .txtadd.Text = lvStudentInfo.SelectedItem.SubItems(3)
    
    .Show 1
End With
End Sub

Private Sub cmdrefresh_Click()
lvStudentInfo.ListItems.Clear
    Call GetStudentRecord
End Sub

Private Sub Form_Load()

title = "System Information"

txtID.Text = 1

Call GetStudentRecord

Connection
sql = "SELECT Owner_ID FROM tbl_Owner"
Set rs = New ADODB.Recordset
rs.Open sql, Conn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
    With rs
        .MoveLast
            txtID.Text = !Owner_ID + Val(1)
        .Close
    End With
End If
    
End Sub

Public Sub GetStudentRecord()
Connection
sql = "tbl_Owner"
Set rs = New ADODB.Recordset
rs.Open sql, Conn, adOpenDynamic, adLockOptimistic
Do Until rs.EOF
    Set lst1 = lvStudentInfo.ListItems.Add(, , rs!Owner_ID)
        With lst1
            .SubItems(1) = rs!Owner_ID
            .SubItems(2) = rs!Owner_Name
            [B].SubItems(3) = rs!Owner_Address[/B] <---*ERROR
            
        End With
    rs.MoveNext
Loop
rs.Close: Set rs = Nothing
End Sub



Private Sub lvStudentInfo_Click()
cmdeditrecord.Enabled = True
cmddeleterecord.Enabled = True

    OwnerID = lvStudentInfo.SelectedItem.Text

End Sub

Private Sub Timer1_Timer()
titledance = Left(title, countertitle)
Me.Caption = titledance
countertitle = countertitle + 1
If countertitle >= Len(title) + 3 Then
    countertitle = 1
    titledance = ""
End If
End Sub

Private Sub txtstudentlastname_Change()
lvStudentInfo.ListItems.Clear
Connection
sql = "SELECT * FROM tbl_Owner WHERE Owner_ID LIKE '" & Trim(txtstudentlastname.Text) & "%'"
Set rs = New ADODB.Recordset
rs.Open sql, Conn, adOpenDynamic, adLockOptimistic
If Not rs.EOF Then
Do Until rs.EOF
    Set lst1 = lvStudentInfo.ListItems.Add(, , rs!Owner_ID)
        With lst1
            .SubItems(1) = rs!Owner_ID
            .SubItems(2) = rs!Owner_Name
            .SubItems(3) = rs!Owner_Address
           
        End With
    rs.MoveNext
Loop
End If
rs.Close: Set rs = Nothing
End Sub

Dani AI

Generated

Good catch by . Building on that fix, the root cause is that the ListView did not have enough columns to accept a third subitem. In VB6 ListView (Report view), the first column is the item’s Text. SubItems(1..N) map to ColumnHeaders 2..N+1. So with three visible columns (ID, Name, Address), only SubItems(1) and SubItems(2) are valid; SubItems(3) would require a fourth column. Also, avoid placing the ID both in Text and again as a subitem unless you truly need it twice.

Initialize the ListView once (e.g., in Form_Load) so the columns match what you plan to display:

Private Sub EnsureColumns()
    With lvStudentInfo
        .View = lvwReport
        .ColumnHeaders.Clear
        .ColumnHeaders.Add , , "Owner ID", 1400
        .ColumnHeaders.Add , , "Owner Name", 2200
        .ColumnHeaders.Add , , "Owner Address", 3000
    End With
End Sub

Then add rows safely. Two extra tips here: (1) handle possible NULLs from ADO, and (2) add subitems explicitly rather than indexing beyond what exists.

Private Function NzStr(v As Variant) As String
    If IsNull(v) Then NzStr = "" Else NzStr = CStr(v)
End Function

Private Sub AddRow(rs As ADODB.Recordset)
    Dim it As ListItem
    Set it = lvStudentInfo.ListItems.Add(, , NzStr(rs!Owner_ID))
    it.ListSubItems.Add , , NzStr(rs!Owner_Name)
    it.ListSubItems.Add , , NzStr(rs!Owner_Address)
End Sub

A few cleanup notes: ensure you always target the same ListView (you have both lvStudentRecord and lvStudentInfo in the code), keep View = lvwReport before populating, and consider using an explicit SELECT (only the needed fields) when opening the recordset. If Owner_ID is numeric, use a numeric WHERE clause (no quotes) when deleting. These small guardrails will prevent 380s and other hard-to-track errors later.

Recommended Answers

All 4 Replies

It because there is no SubItems(3) in your listview..
And why you show Owner ID twice in all of your codes?
modified as following "

Set lst1 = lvStudentInfo.ListItems.Add 
        With lst1
            .Text = rs!Owner_ID
            .SubItems(1) = rs!Owner_Name
            .SubItems(2) = rs!Owner_Address
          
        End With

It because there is no SubItems(3) in your listview..
And why you show Owner ID twice in all of your codes?
modified as following "

Set lst1 = lvStudentInfo.ListItems.Add 
        With lst1
            .Text = rs!Owner_ID
            .SubItems(1) = rs!Owner_Name
            .SubItems(2) = rs!Owner_Address
          
        End With

Oh! Thank you sir! It works. :)

You're welcome. :D
Don't forget to mark this thread as solved.

It because there is no SubItems(3) in your listview..
And why you show Owner ID twice in all of your codes?
modified as following "

Set lst1 = lvStudentInfo.ListItems.Add 
        With lst1
            .Text = rs!Owner_ID
            .SubItems(1) = rs!Owner_Name
            .SubItems(2) = rs!Owner_Address
          
        End With

Oh! Thank you sir! It works. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.