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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help needed to make a unique key! 2

Status
Not open for further replies.

bfamo

Technical User
Feb 16, 2006
132
NO
Still working on making unique keys for my treeview. I've read up on how to make unique keys and also tried making some from examples found in previous posts in the forum.

The method of making keys I currently does not allow me to have nodes with identical names because the key is[/] the nodes name.
Code:
 .Nodes.Add relative:=strNode1Text, relationship:=tvwChild, Key:=strNode2Text, Text:=strVisibleText

To solve this I tried making a key which adds a nuber on the end.
Code:
 .Nodes.Add relative:=strNode1Text, relationship:=tvwChild, Key:=strNode2Text[B] & i[/b], Text:=strVisibleText  [b]|Where i is "i=i+1"|[/b]

I keep getting "Element not found" so I'm obviously doing something wrong.

Is this whole "i=i+1"-idea a good way to go when I want to make unique keys?

I would greatly appreciate any comments or suggestions of not too advanced character, as I am in great need of assistance!! thanks alot in advance!

Here is the code which need to have the keys added to it:
Code:
Function TreeTilsynshistorikk_Fill()

   Dim strMessage As String
   Dim dbs As DAO.Database
   Dim rst As DAO.Recordset
   Dim intVBMsg As Integer
   Dim strQuery1 As String
   Dim strQuery2 As String
   Dim strQuery3 As String
   Dim nod As Object
   Dim strNode1Text As String
   Dim strNode2Text As String
   Dim strNode3Text As String
   Dim strVisibleText As String
      
   Set dbs = CurrentDb()
   strQuery1 = "QryTilsInsTree"
   strQuery2 = "QryTilsInsProdTree"
   strQuery3 = "QryTilsInsProdDatoTree"

With Me![TreeTilsynshistorikk]
      'Fill Level 1
      Set rst = dbs.OpenRecordset(strQuery1, dbOpenForwardOnly)

      Do Until rst.EOF
         strNode1Text = StrConv("Level1" & rst![Initialer], vbLowerCase)
        Set nod = .Nodes.Add(Key:=strNode1Text, Text:=rst![Initialer])
         'Expand the entire node
         nod.Expanded = False
         rst.MoveNext
      Loop
      rst.Close
      
      'Fill Level 2
      Set rst = dbs.OpenRecordset(strQuery2, dbOpenForwardOnly)

      Do Until rst.EOF
         strNode1Text = StrConv("Level1" & rst![Initialer], vbLowerCase)
         strNode2Text = StrConv("Level2" & rst![Navn], vbLowerCase)
         strVisibleText = rst![Navn]
        .Nodes.Add relative:=strNode1Text, relationship:=tvwChild, Key:=strNode2Text, Text:=strVisibleText
          rst.MoveNext
      Loop
      rst.Close
      
'Fill Level 3
       Set rst = dbs.OpenRecordset(strQuery3, dbOpenForwardOnly)

      Do Until rst.EOF
         strNode2Text = StrConv("Level2" & rst![Navn], vbLowerCase)
         strNode3Text = StrConv("Level3" & rst![Dato], vbLowerCase)
         strVisibleText = rst![Dato]
           .Nodes.Add relative:=strNode2Text, relationship:=tvwChild, Key:=strNode3Text, Text:=strVisibleText
          rst.MoveNext
      Loop
      rst.Close
      

   End With
   dbs.Close


End Function
 
I'm back again.

Have a look at this. When you click on the on one of the records, the subform shows more details about the record. If you further press "Vis" you get a report that shows all information about the record you have chosen.

test4.jpg


In this first picture you can se that a record stored under "GRAVDAL" shows the right information also in the subform which it is linked to.

test3.jpg


In the next picture however, you see that when a record with the same date under "APELAND" is chosen, the subform shows information about the record stored under "GRAVDAL".

this is how the code look now:

Code:
Function TreeTilsynshistorikk_Fill()

   Dim strMessage As String
   Dim dbs As DAO.Database
   Dim rst As DAO.Recordset
   Dim rst2 As DAO.Recordset
   Dim rst3 As DAO.Recordset
   Dim intVBMsg As Integer
   Dim nod As Object
   Dim strNode1Text As String
   Dim strNode2Text As String
   Dim strNode3Text As String
   Dim strVisibleText As String
   Dim strSqlLevel2 As String
   Dim strSqlLevel3 As String
   Set dbs = CurrentDb()
   Dim strQuery1 As String
   Dim strQuery2 As String
   Dim strQuery3 As String
   Dim i As Integer
   Dim j As Integer
   Dim k As Integer
   
   strQuery1 = "QryTilsInsTree"
   strQuery2 = "QryTilsInsProdTree"
   strQuery3 = "QryTilsInsProdDatoTree"
   
With Me![TreeTilsynshistorikk]
      'Fill Level 1
      Set rst = dbs.OpenRecordset(strQuery1, dbOpenForwardOnly)

      Do Until rst.EOF
        strNode1Text = StrConv("Level1" & rst![Initialer], vbLowerCase) & i
        Set nod = .Nodes.Add(Key:=strNode1Text, Text:=rst![Initialer])
        strSqlLevel2 = "SELECT DISTINCT Navn FROM QryTilsInsProdTree WHERE Initialer='" & rst![Initialer] & "'"
Set rst2 = dbs.OpenRecordset(strSqlLevel2, dbOpenForwardOnly)
        i = i + 1
        Do Until rst2.EOF
          strNode2Text = StrConv("Level2" & rst2![Navn], vbLowerCase) & j
          strVisibleText = rst2![Navn]
          .Nodes.Add relative:=strNode1Text, relationship:=tvwChild, Key:=strNode2Text, Text:=strVisibleText
          strSqlLevel3 = "SELECT DISTINCT * FROM QryTilsInsProdDatoTree WHERE Navn='" & rst2![Navn] & "' AND Initialer='" & rst![Initialer] & "'"
 j = j + 1
          Set rst3 = dbs.OpenRecordset(strSqlLevel3, dbOpenForwardOnly)
          Do Until rst3.EOF
            strNode3Text = StrConv("Level3" & rst3![Dato], vbLowerCase) & k
            strVisibleText = rst3![Dato]
            .Nodes.Add relative:=strNode2Text, relationship:=tvwChild, Key:=strNode3Text, Text:=strVisibleText
            rst3.MoveNext
            k = k + 1
          Loop
          rst3.Close
          rst2.MoveNext
      Loop
       rst2.Close
       rst.MoveNext
     Loop
      rst.Close
 End With

Is there any kind of information I can provide other than what I have already done to help solve this puzzle?

I'm truly greatful for you guys taking the time to help out here!!
 
The above code fills the tree, it has nothing to do with the NodeClick event. You need to provide the nodeclick code. But I know what it is doing.

From the beginning I told you to USE PRIMARY KEYS AS THE KEYS IN YOUR NODES if you ever had to reference the records represented by the nodes. For the level 3 nodes, you need to remove the dates as keys and use some kind of primary key. The way you set this up it is most likely returning the first date using a dlookup.

Show your code for the click event and change the date to the primary key from that recordset.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top