Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem in ListView Control

Status
Not open for further replies.

pyooi

Programmer
Jan 15, 2003
12
0
0
MY
Hai,

I have a problem in ListView Control.
Im using access 97.

Actually, Im trying to add data to the listview. The coding is like this and it's run successfully in VB:

Private Sub LoadDepartment()
Dim dbs As Database
Dim rs As Recordset
Dim sql As String

Set dbs = CurrentDb()

sql = "SELECT * FROM tblDepartMaintain ORDER BY
DepartCode"
Set rs = dbs.OpenRecordset(sql)

lvwDepartment.ColumnHeaders.Clear
lvwDepartment.ColumnHeaders.Add , , "Department Code",
1000
lvwDepartment.ColumnHeaders.Add , , "Description", 2440
lvwDepartment.View = lvwReport

Dim itmX As ListItem
Dim strkey As String

Do Until rs.EOF
strkey = rs.Fields(0)
Set itmX = lvwDepartment.ListItems.Add(, strkey,
Trim(rs.Fields(0)))
itmX.SubItems(1) = IIf(IsNull(Trim(rs.Fields
(1))), "", Trim(rs.Fields(1)))
rs.MoveNext
Loop
End Sub

****** It will prompt me error message "Key is not unique in Collection". at the "set itmx = ...." line.

What's wrong with my code.

Help Thank you very much
Regards
Eric
 
forgot to mention : im using the microsoft ListView Control version 6.0 that selected from the toolbar
 
I found a solution..

i change to use the microsoft ListView Control version 5.0(SP2) and it work fine.

Thank you
Regards
Eric
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top