Ok i have this form used for registering user for my program (User and Admin type)
When i run it, i get an error that says "Invalid Property Value"
This is my code for my GetUsers function called on my Form_Load event
Public Sub GetUsers()
' On Error GoTo eh
Call con
Set rs = New ADODB.Recordset
With rs
If .State = adStateOpen Then .Close
.Open "Select * From Users Order By UserName;", Dbconn, adOpenKeyset, adLockOptimistic
If rs.EOF = True Then
lvwUser.ListItems.Clear
Exit Sub
End If
lvwUser.ListItems.Clear
Do While .EOF = False
lvwUser.ListItems.Add , , .Fields("ID")
lvwUser.ListItems(lvwUser.ListItems.Count).SubItems(2) = .Fields("UserName")
lvwUser.ListItems(lvwUser.ListItems.Count).SubItems(3) = .Fields("Password")
'lvwUser.ListItems(lvwUser.ListItems.Count).SubItems(3) = .Fields("UserType")
.MoveNext
Loop
End With
Exit Sub
eh:
MsgBox err.Description, vbCritical
End Sub
This is where i am getting the error.
Do While .EOF = False
lvwUser.ListItems.Add , , .Fields("ID")
lvwUser.ListItems(lvwUser.ListItems.Count).SubItems(2) = .Fields("UserName")
lvwUser.ListItems(lvwUser.ListItems.Count).SubItems(3) = .Fields("Password")
'lvwUser.ListItems(lvwUser.ListItems.Count).SubItems(3) = .Fields("UserType")
.MoveNext
Loop
I fix it using this code:
ListView1.ListItems.Add , , rs!ID
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , rs!UserName
ListView1.ListItems.Item(ListView1.ListItems.Count).ListSubItems.Add , , rs!Password
rs.MoveNext
It does fix it but when i reRun my program, there are no records on my listview control
even if i have three records on my database.
I am using a Listview control and view is Report.
Code of my listview:
Private Sub lvwUser_ItemClick(ByVal Item As MSComctlLib.ListItem)
On Error GoTo err
Set rs = New ADODB.Recordset
With rs
If .State = adStateOpen Then .Close
.Open "SELECT * FROM Users where ID = '" & lvwUser.SelectedItem.Text, Dbconn, adOpenKeyset, adLockOptimistic
txtName.Text = .Fields("UserName")
txtPass.Text = .Fields("PassWord")
txtConfirm.Text = .Fields("PassWord")
cboPriv.Text = "Admin"
End With
Exit Sub
err:
MsgBox err.Description, vbCritical
End Sub
What am i missing.