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
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