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!

Finishing my treeview 1

Status
Not open for further replies.

bfamo

Technical User
Feb 16, 2006
132
NO
I have a treeview with three levels. The primary keys in the tables is used as unique keys for the nodes in the tree.

My whole tree is a modified version of Helen Feddema's example, which can be found here.
In this example the tree is connected to a subform, so that you can use the tree as a record selector.

In my previous thread, MajP talked about getting error when using only numeric keys. Therefore I added an "A" first in the unique key, like this:
Code:
strNodeTestText = rst3![[B]Primary key[/B]]
.Nodes.Add relative:=strNode2Text, relationship:=tvwChild, Key:="A" & strNodeTestText, Text:=strVisibleText

Now to the problem:
In order to get the subform to understand what record I'm talking about, the unique key from level 3 is passed over to it. The only problem is that the key contains an "A" e.g. A234 or A933.
All I need to fix this problem is simply a line of code that takes away the "A" in the key(or maybe replaces it with a 0).

I talked to a friend of mine that knows how to do this in C++, but this unfortunately not in vb.

So, any suggestions?

Thanks! :)
 
Hi bfamo,

Try the Replace or Right functions...

HTH, Iain
 
Here is an example of popping up a form based on the node selected.
Code:
Private Sub Xtree_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) - 1)
    stDocName = "frmSelectUnits"
    stLinkCriteria = "txtUICcode = '" & selectedUnit & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
Exit_NodeClick:
    Exit Sub
Err_NodeClick:
    MsgBox Err.Description
    Resume Exit_NodeClick
End Sub
 
Why using the Right and the Len functions when only one (Mid) is needed ?
selectedUnit = Mid(selectedNode.Key, 2)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for replies!

Here is my _NodeClick event:
Code:
Private Sub MyTree_NodeClick(ByVal Node As Object)

   Dim frm As Access.Form
   
   Set frm = Me![subProdInformasjon].Form
   
   If Left(Node.Key, 1) = "A" Then
      Me![txtValgtProd].Value = Node.Key
      frm.RecordSource = "QryTilsProdInfoTree"
      frm.Visible = True
   Else
      frm.Visible = False
   End If
      
End Sub
As you can see the unique key is sent to txtValgtProd if the first letter is "A". However, to use this unique key I then have to remove the "A" as I said previously.

With basis in my _nodeclick, how can this be done?

If I could only get rid of this "A", I can take care of the rest! :D

thanks
 
Hi bfamo,

try

Me![txtValgtProd].Value = Replace(Node.Key,"A","")

Iain
 
thanks!

I put in a zero instead and it worked.

Me![txtValgtProd].Value = Replace(Node.Key,"A","0")

:D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top