Recordset Help (1 Viewer)

BrokenBiker

ManicMechanic
Local time
Today, 12:28
Joined
Mar 22, 2006
Messages
128
I am trying to modify a treeview example (from this site--Treeview 2000). The form's OnLoad event creates a recordset. I would like to use that to capture the PK (AutoNo_Emp) from the selected node, and have it populate an unbound textbox.

This is the OnLoad code:

Code:
    Dim otved As clsTreeViewEnhDefinition

    Me.Caption = Me.Caption

    Set oTV = Me!axProducts.Object
    Set dbs = CurrentDb()

    Set rstEmployee = dbs.OpenRecordset("Select * From tbl_AlphaRoster Order by LName_Emp", dbOpenDynaset)
    
    FillTree
    
    Set oTVE.SetForm = Me
    Set oTVE.SetTreeVewControl = Me.axProducts
    
    Set otved = New clsTreeViewEnhDefinition
    Set otved.rst = rstProduct
    oTVE.AddDefinition otved
    
    Set otved = New clsTreeViewEnhDefinition
    Set otved.rst = rstEmployee
    otved.strNodeType = "e"
    otved.strNodeToDrop = "e"
    otved.strIDField = "AutoNo_Emp"
    otved.strParentIDField = "ReportsTo_Emp"
    oTVE.AddDefinition otved
    
    CommandBars("Treeview").Controls("Forward").Enabled = False
    CommandBars("Treeview").Controls("Back").Enabled = False
    
    mfEnableTimerEvent = True
    Me.TimerInterval = 500
    
    oTV.Nodes("m12").Expanded = True


This is the NodeClick event that is used to populate a label & textbox:

Code:
    Dim h As New clsHistoryInfo
    
    strCurrentNode = nSelectedNode.Key
    
    If Not fSkipHistory Then
        lngHistoryIndex = lngHistoryIndex + 1
        If lngHistoryIndex <= colHistory.Count Then
            colHistory.Item(lngHistoryIndex).strNode = strCurrentNode
            colHistory.Item(lngHistoryIndex).strNodeText = nSelectedNode.Text
        Else
            h.strNode = strCurrentNode
            h.strNodeText = nSelectedNode.Text
            colHistory.Add h
            CommandBars("Treeview").Controls("Forward").Enabled = False
        End If
        CommandBars("Treeview").Controls("Back").Enabled = True
        SetHistoryToolTip
    End If
    
    Me.lblFullPath.Caption = nSelectedNode
    Me.txtSelectedNode = nSelectedNode


Essentially, what I'm trying to do is open a personnel form based on the current node selection. I could create a query to match a "FullName" concoction to the txtSeletectedNode, however...I don't want to create extra objects if I don't have to. Also, I've been struggling w/recordsets and am diving into treeview examples, and I would like to use this to learn a bit more.

So, if anyone has any ideas on how to help, I'm all ears!




---------------



Post edited to include link to sample treeview file
-BB
 
Last edited:

MarkK

bit cruncher
Local time
Today, 10:28
Joined
Mar 17, 2004
Messages
8,198
What I do sometimes is put the ID, a space, and the object type into the Tag property of the node when I create it. Then when the node is clicked
Code:
ID = Split(Node.Tag)(0)
type = Split(Node.Tag)(1)
 

BrokenBiker

ManicMechanic
Local time
Today, 12:28
Joined
Mar 22, 2006
Messages
128
Thansk for the response, Lagbolt. I ended up figuring it out, but not in the way originally intended.

Basically, I changed the node text to include the PK, and then I created a second unbound textbox and set it equal to:

Code:
=Left([txtSelectedNode],InStr([txtSelectedNode]," "))

to separate the PK, and I use that to open the form to the specific record based on the selected node w/this click fx:

Code:
DoCmd.OpenForm "frmMain_Employees", acNormal, , "[AutoNo_Emp]=" & Me!txtAutoNo_Emp, acFormEdit, acWindowNormal, ""
 

MarkK

bit cruncher
Local time
Today, 10:28
Joined
Mar 17, 2004
Messages
8,198
Cool!
FWIW, when opening a form I don't explicitly provide parameters that'll default to the same values. I think this makes the statement more readable ...
Code:
DoCmd.OpenForm "frmMain_Employees", , , "[AutoNo_Emp]=" & Me!txtAutoNo_Emp
Cheers,
 

Users who are viewing this thread

Top Bottom