[RESOLVED] ListView Invalid Key - Why?
I have this code and I am getting the above error msg (Err.Num 35603)
Code:
Do While Not rs.EOF
Set lvwItem = lvwMain.ListItems.Add(, rs!Memb_ID.Value, rs!First_Name.Value & " " & _
IIf(rs!Middle_Name.Value = "", rs!Surname.Value, rs!Middle_Name.Value & " " & _
rs!Surname.Value))
rs.MoveNext
Loop
rs!Memb_ID.Value is the primary key in the database.
Can't you use this?
Re: ListView Invalid Key - Why?
The key needs to be a string so try
Cstr(rs!Memb_ID.Value)
Re: ListView Invalid Key - Why?
Quote:
Originally Posted by MartinLiss
The key needs to be a string so try
Cstr(rs!Memb_ID.Value)
I did try this before, and since, but it still throws the same error!
Re: ListView Invalid Key - Why?
Do you get any of the records entered into the listview or is it a specific record where it pukes?
Re: ListView Invalid Key - Why?
It throws the error when trying to load the first record.
This is the complete code:
Code:
'load members into listview
Set rs = New ADODB.Recordset
strSQL = "SELECT First_Name, Middle_Name, Surname, Memb_ID FROM tbl_Membership"
strSQL = strSQL & " ORDER BY Surname"
rs.Open strSQL, cn, adOpenForwardOnly, adLockReadOnly, adCmdText
Do While Not rs.EOF
Set lvwItem = lvwMain.ListItems.Add(, CStr(rs!Memb_ID.Value), rs!First_Name.Value & " " & _
IIf(rs!Middle_Name.Value = "", rs!Surname.Value, rs!Middle_Name.Value & " " & _
rs!Surname.Value))
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Re: ListView Invalid Key - Why?
Looks like its the syntax of your recordset reference to the field. You can not use the field name with the dot value. Use this syntax...
rs.Fields("First_Name").Value
Re: ListView Invalid Key - Why?
Quote:
Originally Posted by RobDog888
Looks like its the syntax of your recordset reference to the field. You can not use the field name with the dot value. Use this syntax...
rs.Fields("First_Name").Value
I now have this and still the same error! :confused:
Code:
Set lvwItem = lvwMain.ListItems.Add(, CStr(rs.Fields("Memb_ID").Value), rs.Fields("First_Name").Value & " " & _
IIf(rs.Fields("Middle_Name").Value = "", rs.Fields("Surname").Value, _
rs.Fields("Middle_Name").Value & " " & rs.Fields("Surname").Value))
Re: ListView Invalid Key - Why?
Your key can't start with a number. Plain and simple....
try "K:" & CStr(rs.Fields("Memb_ID").Value) as your key.... PITA, but I know it works.... been working for us for over 10 years.
-tg
Re: ListView Invalid Key - Why?
Thanks Techgnome, that worked.
One to remember ;)
BTW what does PITA stand for??
Re: [RESOLVED] ListView Invalid Key - Why?
[Edited by MartinLiss]
Glad it's working.
-tg