Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Replacing a node on a TreeView control

Posted on 2004-09-29
4
Medium Priority
?
765 Views
Last Modified: 2008-02-01
Hello,

Semiconductor material grown in crystals; the crystals are then cut first into sections, then each section into wafers. A crystal of say, 350mm length, could be cut at 100mm and 200mm creating three sections labeled 0/100, 100/200, 200/350. Wafers cut from the 0/100 section are numbered 1, 2,...100; from the 100/200 section they're numbered 101, 102,...,200  and so on.

I am using a treeview control to display the records for the crystals. Top level (parent) is the crystal itself, next level (child) is sections of the crystal, and the last level (grandchild) are the wafers.

A crystal section can be taken from inventory and cut into two pieces. For example, the 100/200 section can be cut at 175 creating two sections: 100/175, and 175/200. Any wafer records for the original section must be edited so that they will stay associated with the appropriate new section (i.e. wafer 120 must end up a child of the 100/175 section, while wafer 180 must end up a child of the 175/200 section).

All of this works fine.  My problem is at the last step where I want to update the treeview to reflect the change. You can't just requery the control. Also (and please correct me if I'm wrong here), the treeview just represents a view of the data - changing the tree doesn't change the data. That is to say, the data manipulation and the treeview manipulation are done separately.  

I am attempting to:

1. delete the selected section from the treeview
2. add the two new sections in its place
3. populate each new section (add the wafers)

I am getting stuck, mainly I think with the treeview syntax.  Here's most of what I have so far...

Dim objTree As TreeView
Dim nCurrentTreeNode, currentnode, pnode As node


Set objTree = Forms!frmFabrication!tvCrystal.Object

<data manipulation code>

' treeview manipulation
        Set pnode = objTree.SelectedItem.Parent
        objTree.Nodes.Remove (objTree.SelectedItem.Key)
        Set currentnode = objTree.Nodes.Add(pnode, tvwChild, "c" & sectionID, sectionNo)
            'Add any wafers for this section.
 (*)   AddGrandChildren currentnode, currentnode.Key
        Set currentnode = objTree.Nodes.Add(pnode, tvwChild, "c" & newsectionID, newsectionNo)
        'Add any wafers for this section.
        AddGrandChildren currentnode, currentnode.Key
        currentnode.Expanded = True
        currentnode.Selected = True

<then come closing statements>

<The AddGrandChildren routine...>

Sub AddGrandChildren(nodBoss As node, CSN)
    On Error GoTo ErrAddGrandChildren

    Dim nodCurrent As node
    Dim objTree As TreeView
    Dim bk As String
    Dim db As Database
    Dim rst As Recordset

    'Create a reference to the TreeView control.
    Set objTree = Me!tvCrystal.Object
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("SELECT * FROM qryFabricationList2 WHERE [XtalSectionID]=" & CSN)
    Do Until rst.EOF
        'Extract the wafer name.
        strText = rst![FabWaferNo]
        'Add as a child node to the tree.
        Set nodCurrent = objTree.Nodes.Add(nodBoss, tvwChild, "g" & _
            rst![FabWaferNo], rst![WaferNumber])
        'Find the next section.
        rst.MoveNext
    Loop
   
    rst.Close
    Set rst = Nothing

ExitAddGrandChildren:
    Exit Sub

ErrAddGrandChildren:
    MsgBox "Can't add child:  " & Err.Description, vbCritical, _
        "AddGrandChildren(nodBoss As Node) Error:"
    Resume ExitAddGrandChildren
End Sub

<end code>

The code gets to (*) and then I get an error: ByRef argument type mismatch.

Where am I going wrong?

Firebird-sc

0
Comment
Question by:firebird-sc
  • 2
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
shanesuebsahakarn earned 760 total points
ID: 12183311
Try:
Dim nCurrentTreeNode As Node, currentnode As Node, pnode As node

At present, your first two vars are dimmed as variants, not node objects. Does this make a difference?
0
 
LVL 2

Author Comment

by:firebird-sc
ID: 12184394
Yes! It did make a difference.  I thought the way I had it before it would set all three to Node objects.

thank you very much! I was stuck on that for a while and there's not a lot out there on the TreeView to reference.

firebird-sc
0
 
LVL 41

Expert Comment

by:shanesuebsahakarn
ID: 12184428
It's actually a limitation of VBA. Unless you include the As <data type> against each variable name, the variable is declared as a variant. For example:

Dim I,J,K As Long
will only dim K as long, the other two are variants. You'd need:
Dim I As Long, J As Long, K As Long
0
 
LVL 2

Author Comment

by:firebird-sc
ID: 12184498
It's never given me a problem until now - I guess historically most of my variables have been variants!  

In ASP, on the other hand, I get errors when I INCLUDE the "As <datatype>" part, so I write all declarations:

dim var1
dim var2
dim var3
etc.

Seems kind of loose and sloppy to me, but it works.

Thanks again.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question