-
Nov 23rd, 2020, 04:55 PM
#1
Thread Starter
Hyperactive Member
-
Nov 23rd, 2020, 07:09 PM
#2
Re: Error loading records into ListView
What is the value of that field at the time the error occurs?
What data type is the field in the DB?
Is the value Null?
-
Nov 24th, 2020, 12:31 AM
#3
Thread Starter
Hyperactive Member
Re: Error loading records into ListView
It's a String in the database e.g. Circovirus or PBFD Virus.
The value is not NULL. While trying to figure out why the error occurred I put a message box on the line before the error line showing the value and it's correct.
-
Nov 24th, 2020, 01:37 AM
#4
Re: Error loading records into ListView
I do not see anything wrong with the line that adds to the listview and if it is a text field in the db then there should only be a type issue if the field has a null value in it.
That said I see you are using a select * but only using 1 field from the table. You should be selecting only that field since that is all you are using and personally I would use the index number of that field rather than the name in the assignment as using the number is slightly faster but I would not think either of those things are related to your error message.
-
Nov 24th, 2020, 01:45 AM
#5
Thread Starter
Hyperactive Member
Re: Error loading records into ListView
If I put On Error Resume Next before the Do While loop it loads the records into the ListView. I can see them in the ListView but if I select one of them the check mark in the checkbox appear and the program crash with 'Runtime error 35603: Invalid key'.
So I added the same value in the key parameter but same error happens.
-
Nov 24th, 2020, 03:34 AM
#6
Re: Error loading records into ListView
as you do not use the listitem objects, try adding the items to the listview without setting to the listitem
also to avoid any problem with empty record fields, try add a nullstring
Code:
LvwInclude.ListItems.Add , , vbnullstring & rsTestType("OPT_Option").Value
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 24th, 2020, 05:00 AM
#7
Thread Starter
Hyperactive Member
Re: Error loading records into ListView
Originally Posted by westconn1
as you do not use the listitem objects, try adding the items to the listview without setting to the listitem
also to avoid any problem with empty record fields, try add a nullstring
Code:
LvwInclude.ListItems.Add , , vbnullstring & rsTestType("OPT_Option").Value
Loading them like this does load without error but still errors (Run-time error 35603: Invalid key) when I click on the checkboxes. No error when I click on the words themselves.
-
Nov 24th, 2020, 06:19 AM
#8
Re: Error loading records into ListView
How is the Listview initialized?
Which properties have you set?
What code do you have in the ListView1_ItemCheck event?
Code:
Option Explicit
Private Sub Form_Load()
With ListView1
.Checkboxes = True
.View = lvwReport
.ColumnHeaders.Add , , "Column 1"
.ColumnHeaders.Add , , "Column 2"
.ColumnHeaders.Add , , "Column 3"
End With
End Sub
Private Sub Command1_Click()
With ListView1.ListItems.Add(, , "Yoohoo!")
.SubItems(1) = "What's up?"
.SubItems(2) = Time
End With
End Sub
Private Sub ListView1_ItemCheck(ByVal Item As MSComctlLib.ListItem)
' what code do you have here??
End Sub
Last edited by Arnoutdv; Nov 24th, 2020 at 06:27 AM.
-
Nov 24th, 2020, 11:32 AM
#9
Thread Starter
Hyperactive Member
Re: Error loading records into ListView
Added to the form and set the Checkboxes property to True and the View property to Report. But I only have one column so no SubItems.
I thought I had no code in ItemCheck yet but see I have tried to access the ListView.ListItems.Item(Item).Checked property. Going to disable the ItemCheck and see what happens then.
-
Nov 24th, 2020, 12:04 PM
#10
Thread Starter
Hyperactive Member
Re: Error loading records into ListView
Ok. I see that the Invalid key error message is generated by ListView.ListItems.Item(Item).Checked. Will have to look into that next.
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
|