Replacing Nodes (1 Viewer)

nick.tait

Registered User.
Local time
Today, 10:09
Joined
May 25, 2009
Messages
16
Hi everyone,
Is there anyway to replace the nodes in a treeview instead of adding them to the treeview so that i dont get a 'Key is not unique in collection' error every time i try to run the code? My code is below. Thank you all in advance

Option Compare Database
Option Explicit
Private Sub Custodian_History_Form_Enter()
Dim db As DAO.Database
Dim db2 As DAO.Database
Dim rs As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim strQuery1 As String
Dim strQuery2 As String
Dim nod As Object
Dim strNode1Text As String
Dim strNode2Text As String
Dim strVisibleText As String
Dim strMessage As String
Dim intVBMsg As Integer
Dim intCounter As Integer
Dim stringcount As String


Me.[custodian history form].Nodes.Add Text:="Custodian History", Key:="Custodianhistory51"

strQuery2 = "select DISTINCT [Asset Name] from [Asset Master]"
Set db = CurrentDb
Set rs2 = db.OpenRecordset(strQuery2)
Do Until rs2.EOF
strNode2Text = StrConv("Level1" & rs2![Asset Name], vbLowerCase)
strVisibleText = rs2![Asset Name]
'if model name is null, will have problem
If IsNull(rs2![Asset Name]) Then
MsgBox "number is null"
strVisibleText = "no name"
End If
stringcount = CStr(intCounter)
strNode2Text = strNode2Text + stringcount
Set nod = Me.[custodian history form].Nodes.Add(Relative:="Custodianhistory51", relationship:=tvwChild, Key:=strNode2Text, Text:=strVisibleText)
rs2.MoveNext
Loop
rs2.Close
'rs.MoveNext

strQuery1 = "select DISTINCT AssetNumber From [Asset Master]"
intCounter = 1
With Me![custodian history form]
Set db2 = CurrentDb()
Set rs = db2.OpenRecordset(strQuery1)
Do Until rs.EOF
Debug.Print rs!AssetNumber
strNode1Text = StrConv("level2" & rs!AssetNumber, vbLowerCase)
Set nod = .Nodes.Add(Relative:=strNode1Text, relationship:=tvwChild, Key:=strNode1Text, Text:=rs!AssetNumber)
nod.Expanded = False

Loop
rs.Close
End With
End Sub
 

Endre

Registered User.
Local time
Today, 02:09
Joined
Jul 16, 2009
Messages
137
Hi Nick, you don't seem to have a lot of luck with your treeview posts. I have worked extensively with TreeView, Nodes, Drag&Drop and may be to help you.

As you seem to have several problems, some seem relatively "old", would you like to let me know which ones are still outstanding, and which ones are closed? Just reply to this with the URL's of the ones you need looking at in the order they need fixing. If you could also give me a breif description of your app and what it does would also be helpful...

See a new look for Northwind in attached image. This works the same to almost any database you connect to. This just happens to be Northwind.
 

Attachments

  • untitled.jpg
    untitled.jpg
    99.8 KB · Views: 93

Users who are viewing this thread

Top Bottom