Trying to populate a treeview. Works if a record is not deleted from the database. However, once a record or two are deleted the treeview will not populate because of the 'index out of bounds' msg.
There are three levels (nodes?) for this treeview. The first is to show the artist, the second his/her albums and the third their recordings. All artists have Albums but not all recordings have been entered. Because of the error, if an artist has multiple albums only the first in the DB shows up.
The DB has the ArtistID and AlbumID (two tables) set as autonumber. If they are changed to Integers, the gap between the IDs can be diminished, ie if the second last artist has an ID of 8 and the next ID is 11, an error occurs. If the ID of 11 is changed to 9, the tree view loads with no apparent problems.
I found this code to load the treeview at
I thought of incrementing the IDs manually but that does not make sense since if any Artists/Albums are deleted the same problem occurs.
There are three levels (nodes?) for this treeview. The first is to show the artist, the second his/her albums and the third their recordings. All artists have Albums but not all recordings have been entered. Because of the error, if an artist has multiple albums only the first in the DB shows up.
The DB has the ArtistID and AlbumID (two tables) set as autonumber. If they are changed to Integers, the gap between the IDs can be diminished, ie if the second last artist has an ID of 8 and the next ID is 11, an error occurs. If the ID of 11 is changed to 9, the tree view loads with no apparent problems.
I found this code to load the treeview at
Code:
' Open a recordset and loop through it to fill tvwMusic
' Fill Level 1 using ArtistID as Key property
If rst.State = adStateOpen Then rst.Close
rst.Open "tblArtists", cn, adOpenForwardOnly
Do Until rst.EOF
frmSSTab.tvwMusic.Nodes.Add , , "a" & rst.Fields("ArtistID").Value, _
rst.Fields("DisplayName").Value '& " " & rst.Fields("Lastname").Value
rst.MoveNext
Loop
rst.Close
' Fill Level 2
rst.Open "tblAlbums ORDER BY Album", cn, adOpenDynamic
Do Until rst.EOF
' Link to level 1 by referencing the ArtistID key and set
' the Node as a child node of Level 1. Use "o" and the StrConv()
' function in the new key property for Level 2, because AlbumID is a numeric field
sOrderKey = StrConv("o" & rst.Fields("AlbumID").Value, vbLowerCase)
frmSSTab.tvwMusic.Nodes.Add rst.Fields("ArtistID").Value, tvwChild, sOrderKey, _
rst.Fields("Album").Value
rst.MoveNext
Loop
rst.Close
' Fill level 3
rst.Open "tblTracks", cn, adOpenForwardOnly
Do Until rst.EOF
' Link to Level 2 by referencing the sOrderKey key and set
' the node as a child node of level 2.
' Product Key is made alpha with "p" for parsing
sOrderKey = StrConv("o" & rst!AlbumID, vbLowerCase)
sProductID = StrConv(sOrderKey & "p" & rst.Fields("TrackID").Value, vbLowerCase)
frmSSTab.tvwMusic.Nodes.Add sOrderKey, tvwChild, sProductID, rst.Fields("Title").Value & ""
rst.MoveNext
Loop
rst.Close
I thought of incrementing the IDs manually but that does not make sense since if any Artists/Albums are deleted the same problem occurs.