Solved

Replacing a node on a TreeView control

Posted on 2004-09-29
4
687 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 190 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now