I am using VB6, ADO and Access 2002.

I am trying to write the first three fields from a Db to a listview;
Fields names are:
First_Name, Middle_Name, Surname.

Now the name may, or may not have a middle name, and I think this is what is causing me the problem

I am getting something wrong with the writing to the Listview, but I'm not sure why.

I am getting the error

Invalid property value

when the second item is to be added.

My Code:
vb Code:
  1. Set rs = New ADODB.Recordset
  2. Set cn = New ADODB.Connection
  3. cn.ConnectionString = strConnection & App.Path & "\Membership.mdb"
  4. cn.Open
  5.  
  6. strSQL = "SELECT First_Name, Middle_Name, Surname FROM tbl_Membership "
  7. strSQL = strSQL & " WHERE First_Name <> '""'"
  8. rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
  9.  
  10. i = 1
  11.  
  12. Do While Not rs.EOF
  13.     If rs!Middle_Name <> "" Then
  14.         If i = 1 Then
  15.             Set lvwItem = lvwMembers.ListItems.Add(, , rs!First_Name & " " & rs!Middle_Name & " " & rs!Surname)
  16.         Else
  17.             lvwItem.SubItems(i) = rs!First_Name & " " & rs!Middle_Name & " " & rs!Surname
  18.         End If
  19.     Else
  20.         If i = 1 Then
  21.             Set lvwItem = lvwMembers.ListItems.Add(, , rs!First_Name & " " & rs!Surname)
  22.         Else
  23.             lvwItem.SubItems(i) = rs!First_Name & " " & rs!Surname
  24.         End If
  25.     End If
  26.    
  27.     i = i + 1
  28.     rs.MoveNext
  29. Loop
  30. Set rs = Nothing
  31. cn.Close
  32. Set cn = Nothing