
Will somebody tell me what I am doing wrong with this ListView Control
My objective is to build a report based Listview showing all the customers
in my Customer Table
I want to uniquely identify each row of the collection with the primary key
from the customer table. So that i can reference that when a row is
selected.
My code, however, generates a runtime error: 35603 Invalid key.
Here is a description of the .Add method from my MSDN library:
===================================================================
object.Add(index, key, text, icon, smallIcon)
The Add method syntax has these parts:
Part Description
object Required. An object expression that evaluates to a ListItems
collection.
index Optional. An integer specifying the position where you want to
insert the ListItem. If no index
is specified, the ListItem is added to the end of the
ListItems collection.
key Optional. A unique string expression that can be used to access
a member of the collection.
additionally:
string expression
Any expression that evaluates to a sequence of contiguous characters.
Elements of a string expression can include a function that returns a
string, a string literal, a string constant, a string variable, a string
Variant, or a function that returns a string Variant (VarType 8).
========================================================================
I am presenting the statement with what I believe to be a unique string. The
field rsCustomer!ID is a unique primary key and I am casting it as a string
expression
Here is the code:
=========================================================================
Private Sub Form_Load()
Dim I As Integer
Dim J As Integer
cmdSelect.Enabled = False
de1.cn1.Open
de1.rsCustomer.Open , , adOpenStatic, adLockReadOnly
With lv1
.View = lvwReport
.FullRowSelect = True
For I = 1 To 8
.ColumnHeaders.Add
.ColumnHeaders(I).Text = de1.rsCustomer.Fields(I).Name
Next I
End With
With de1.rsCustomer
.MoveFirst
I = 1
Dim strTmp As String
Do Until .EOF
'Here is the problem line. I have tried Str(!ID), CStr(!ID), and
setting a string variable to !ID prior to
'invoking the line as in strTmp = Str(!Id) ... lv1.ListItems.Add ,
strTmp
' As far as I am concerned, setting the value of index to I is
extraneous.
'I can't use I to identify the record in the table
lv1.ListItems.Add I, Str(!ID)
lv1.ListItems(I).Text = .Fields(1).Value
For J = 2 To 8
lv1.ListItems(I).ListSubItems.Add
lv1.ListItems(I).ListSubItems(J - 1).Text = .Fields(J).Value &
""
Next J
.MoveNext
I = I + 1
Loop
End With
lv1.Sorted = True
Me.Show
End Sub
===============================================================