Treeview error 35602 in Access 2007

R

Radtherapy

Whenever I try to populate my Treeview control, I get an error 35602 "Key is
not unique in collection". The table I am populating from has 1 record and
the primary key is an autonumber. Here is the code:

Private Sub FavMenu()
'This procedure populates the TreeView control for User's Favorite Items
On Error GoTo ErrFavMenu

Dim db As Database
Dim rstf As Recordset
Dim nodfCurrent As Node, nodfRoot As Node
Dim objfTree As TreeView
Dim strfText As String, bk As String, strfRecSet As String

strfRecSet = "SELECT DISTINCT MenuSubID, SubTitle, ActiveOpt FROM
tblExecMenuFavs where UserID = " & glbUserID & " ORDER BY SubTitle"
Set db = CurrentDb
Set rstf = db.OpenRecordset(strfRecSet, dbOpenDynaset, dbSeeChanges)
Set objfTree = Me.xTreeFav.Object
Me!xTreeFav.Font = "Franklin Gothic Medium"
Me!xTreeFav.Font.Size = "11"
While (Not rstf.EOF)
strfText = rstf![SubTitle]
Set nodfCurrent = objfTree.Nodes.Add(, , "k" & rstf("MenuSubID"),
strfText)
rstf.MoveNext
Wend

ExitFavMenu:
rstf.Close
Set rstf = Nothing

Exit Sub

ErrFavMenu:
If Err.Number = 35602 Then
MsgBox Err.Number & " " & Err.Description
Resume Next
Else
MsgBox Err.Number & " " & Err.Description, vbCritical, "Form_Load"
Resume ExitFavMenu
End If
End Sub

This happened to me once before a few months ago, and I absolutely cannot
remember what I had to do to fix it - any help and I promise I will write the
solution down and store it in a locked vault.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top