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