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