ClaraBarton
Registered User.
- Local time
 - Today, 00:43
 
- Joined
 - Oct 14, 2019
 
- Messages
 - 754
 
		Code:
	
	
	Private Sub tvCookbooks_NodeClick(ByVal Node As Object)
On Error GoTo ErrorHandler
    Dim dbs As DAO.Database
    Dim rs As Recordset
    Dim KeyPart As Integer
    Set dbs = CurrentDb
    Set rs = Me.RecordsetClone
    
    KeyPart = Val(Right(Node.key, Len(Node.key) - 1))
 
     rs.FindFirst "[RecipeID] = " & KeyPart
        
        Debug.Print KeyPart
        Me.Bookmark = rs.Bookmark
    Set rs = Nothing
        
cleanup:
    Exit Sub
ErrorHandler:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume cleanup
End Sub
Private Sub tvCookbooks_Load()
On Error GoTo ErrorHandler
 
Dim db As DAO.Database
Dim rsCookbooks As DAO.Recordset
Dim rsChapters As DAO.Recordset
Dim rsRecipes As DAO.Recordset
Dim strSql As String
'Dim intDistance As Integer
' Clear the tree
    Me.tvCookbooks.Nodes.Clear
    Set db = CurrentDb()
'add the cookbooks
    strSql = "SELECT cookbookid, name " & _
        "FROM t_cookbook " & _
        "ORDER BY name"
    Set rsCookbooks = db.OpenRecordset(strSql)
    Do Until rsCookbooks.EOF
         Me.tvCookbooks.Nodes.Add _
            key:="CB" & rsCookbooks!cookbookid, _
            Text:=rsCookbooks!Name
        rsCookbooks.MoveNext
    Loop
'add the chapters
    strSql = "SELECT cookbookchapterid, name, cookbookid " & _
        "FROM t_cookbookchapter " & _
        "ORDER BY name"
    Set rsChapters = db.OpenRecordset(strSql)
    Do Until rsChapters.EOF
        Me.tvCookbooks.Nodes.Add _
            Relative:="CB" & rsChapters!cookbookid, _
            Relationship:=tvwChild, _
            key:="CH" & rsChapters!cookbookchapterid, _
            Text:=rsChapters!Name
        rsChapters.MoveNext
    Loop
'now the recipes
    strSql = "SELECT t_recipe.cookbookid, t_recipe.recipeid, " & _
        "t_recipe.recipename, t_recipe.cookbookchapterid " & _
        "FROM t_recipe " & _
        "ORDER BY t_recipe.cookbookchapterid"
    
    Set rsRecipes = db.OpenRecordset(strSql)
        
        Dim stCBCH As String
  
        Do Until rsRecipes.EOF
            If Nz(rsRecipes!cookbookchapterid, 0) = 0 Then
                stCBCH = "CB" & rsRecipes!cookbookid
            Else
                stCBCH = "CH" & rsRecipes!cookbookchapterid
            End If
            
            Me.tvCookbooks.Nodes.Add _
                Relative:=stCBCH, _
                Relationship:=tvwChild, _
                key:="R" & rsRecipes!recipeid, _
                Text:=rsRecipes!recipename
            rsRecipes.MoveNext
       Loop
    
GoTo cleanup
cleanup:
On Error Resume Next
    rsCookbooks.Close
    Set rsCookbooks = Nothing
    rsChapters.Close
    Set rsChapters = Nothing
    rsRecipes.Close
    Set rsRecipes = Nothing
    Set db = Nothing
Exit Sub
ErrorHandler:
    MsgBox "Error " & Err.Number & ": " & Err.Description
    Resume cleanup
End Sub
	The treeview here looks nice but doesn't work.... Some of the recipes come up right. Some don't at all and some bring up a random recipe. I suspect it has to do with levels, like some cookbooks do not have chapters and some do. They seem to look right, just don't work right. If nothing worked at all I'd get it but this has me buffaloed. I notice levels are a field in the cookbooks but I don't know where to use them.