hI Majp,
Thanks for the reply, I am getting a message to say the form has been cancelled. I am guessing that the underling query of the form is not picking up the stLinkCriteria, so I thought I should give you some more info.Below is the Treeview Code, the Parent being the MemberID, Child is the SiteID and the Child of Child is the ActivityID, so I need the ActivityID to be selected when opening the form so the correct record is selected.
Private Sub Form_Open(Cancel As Integer)
SetupTreeview
CreateKAMNodes
CreateSiteNodes
CreateSchemeNodes
End Sub
Private Sub SetupTreeview()
With Me.DatabaseTreeview
.Style = tvwTreelinesPlusMinusText
.LineStyle = tvwRootLines
.Indentation = 240
.Appearance = ccFlat
.HideSelection = False
.BorderStyle = ccFixedSingle
.HotTracking = True
.FullRowSelect = True
.Checkboxes = False
.SingleSel = False
.Sorted = False
.Scroll = True
.LabelEdit = tvwManual
.Font.Name = "Tahoma"
.Font.Size = 8
End With
End Sub
Private Sub CreateKAMNodes()
Dim rst As DAO.Recordset ' recordset for category data
' open the recordset for categories
Set rst = CurrentDb.QueryDefs!QryLookupKAMList.OpenRecordset
' loop through the rows in the recordset
rst.MoveFirst
Do Until rst.EOF
Me.DatabaseTreeview.Nodes.add Text:=rst!MemberName, _
Key:="KAM=" & CStr(rst!MemberID)
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
Private Sub CreateSiteNodes()
Dim rst As DAO.Recordset ' recordset for product data
' open the recordset for products
Set rst = CurrentDb.QueryDefs!QryTreeSiteNames.OpenRecordset
' loop through the rows in the recordset
rst.MoveFirst
Do Until rst.EOF
Me.DatabaseTreeview.Nodes.add Relationship:=tvwChild, _
Relative:="KAM=" & CStr(rst!MemberID), _
Text:=rst!SiteName, Key:="Site=" & CStr(rst!SiteID)
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
Private Sub CreateSchemeNodes()
Dim rst As DAO.Recordset ' recordset for product data
' open the recordset for products
Set rst = CurrentDb.QueryDefs!QryTreeSchemeNames.OpenRecordset
' loop through the rows in the recordset
rst.MoveFirst
Do Until rst.EOF
Me.DatabaseTreeview.Nodes.add Relationship:=tvwChild, _
Relative:="Site=" & CStr(rst!SiteID), _
Text:=rst!SchemeName, Key:="ActivityID=" & CStr(rst!ActivityID)
rst.MoveNext
Loop
rst.Close
Set rst = Nothing
End Sub
I have modified your code as follows
Private Sub DatabaseTreeview_NodeClick(ByVal selectedNode As Object)
On Error GoTo Err_NodeClick
Dim stDocName As String
Dim stLinkCriteria As String
Dim selectedUnit As String
selectedUnit = right(selectedNode.Key, Len(selectedNode.Key) - 11)
stDocName = "FrmAccountSchemeCFLDetails"
stLinkCriteria = "ActivityID = '" & selectedUnit & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_NodeClick:
Exit Sub
Err_NodeClick:
MsgBox Err.Description
Resume Exit_NodeClick
End Sub
Not sure if my Treecode is the best way/fastest way to do but it works.
any thoughts where I am going wrong?
Thanks
cneill