|
-
Jan 18th, 2008, 11:18 AM
#1
Thread Starter
Frenzied Member
[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?
-
Jan 18th, 2008, 11:53 AM
#2
Re: ListView Invalid Key - Why?
The key needs to be a string so try
Cstr(rs!Memb_ID.Value)
-
Jan 18th, 2008, 12:51 PM
#3
Thread Starter
Frenzied Member
Re: ListView Invalid Key - Why?
 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!
-
Jan 18th, 2008, 12:53 PM
#4
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?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 18th, 2008, 12:58 PM
#5
Thread Starter
Frenzied Member
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
-
Jan 18th, 2008, 01:07 PM
#6
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 18th, 2008, 02:07 PM
#7
Thread Starter
Frenzied Member
Re: ListView Invalid Key - Why?
 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!
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))
-
Jan 18th, 2008, 02:11 PM
#8
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
-
Jan 18th, 2008, 02:22 PM
#9
Thread Starter
Frenzied Member
Re: ListView Invalid Key - Why?
Thanks Techgnome, that worked.
One to remember
BTW what does PITA stand for??
-
Jan 18th, 2008, 03:16 PM
#10
Re: [RESOLVED] ListView Invalid Key - Why?
[Edited by MartinLiss]
Glad it's working.
-tg
Last edited by MartinLiss; Jan 18th, 2008 at 03:32 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|