TreeView_NodeCheck compile error - procedure declaration does not match description of event or procedure having the same name RRS feed

  • Question

  • Hi! I am quite new to programming in VBA, and I have this project in Excel with a treeview. Now, I am using a code (with help from sources I found on the internet) on how to check / uncheck the children when the parent node is selected. I know my code isnt optimized, but it works on my computer. However, when I distributed it to my peers, it suddenly shows the Compile Error: procedure declaration does not match description of event or procedure having the same name. The error is on the procedure declaration itself, but I just selected this from the dropdown boxes and didn't change anything.

    So we tried to experiment and rewrite the declaration on the computer where the error occurred. We wrote the exact same thing, and poof! It worked! But when they sent me back this file, the error is now transferred to my computer. I am really not sure what is wrong, but I suspect that it is the difference on the mscomctl.ocx file. Their version is while mine is I have not yet changed my version to theirs as I do not have admin rights on my work computer. But I would like to hear some thoughts on what you think could be done, or if it is not necessary to change the version of my mscomctl.ocx file. I also read on some forums that it might be good to do late binding to avoid problems with diff versions, although I am not really well-versed to do it on my code.

    Thanks for your help!

    Private Sub TreeView1_NodeCheck(ByVal Node As MSComctlLib.Node)
    Dim iChild, yChild As Integer
    Dim nodX, nodY As Node
        If Node.Children <> 0 Then
        'if there are children present, then Node is a parent
            Set nodX = Node.Child
            For iChild = 1 To Node.Children
                nodX.Checked = Node.Checked
                If nodX.Children <> 0 Then
                'if there are children present, then node is a child with subchildren
                    Set nodY = nodX.Child
                    For yChild = 1 To nodX.Children
                        nodY.Checked = nodX.Checked
                        Set nodY = nodY.Next
                        'if a subchild is checked, then nodX, which is a child, should be checked
                        'do this loop to check if any of the subchildren is checked, then check the child
                 End If
                'if a child is checked, then Node, which is a parent, should be checked
                'do this loop to check if any of the children is checked, then check the parent
                Set nodX = nodX.Next
            If Not Node.Parent Is Nothing Then
            'if the parent of the Node does exist, then it is a child
                If Node.Checked Then
                    'check the parent and skip the loop if the current node is checked.
                    Node.Parent.Checked = True
                    Node.Parent.Checked = False
                    'if the Node, which is a child, is unchecked, then uncheck the parent
                    'however, proceed with the loop below to see if other children are checked. If yes, check the parent
                    Set nodX = Node.Parent.Child
                    Do Until nodX Is Nothing
                        If nodX.Checked Then
                            'at least one other child node is checked so check the parent and exit the loop
                             Node.Parent.Checked = True
                             Exit Do
                         End If
                         Set nodX = nodX.Next
                End If
            End If
         End If
    End Sub

    Wednesday, November 25, 2020 8:44 AM

All replies

  • I don't think that version difference is the problem. Silly question first but are you both using the same actual control, in your respective systems which of the following is ticked in Tools / References (both should be the former)

    MSComctlLib   Microsoft Windows Common Controls 6.0 (SP6)
    MSComCtl2     Microsoft Windows Common Controls-2 6.0 (SP6)

    Wednesday, November 25, 2020 12:01 PM
  • We have the same exact references, using both MSComctlLib :(
    Wednesday, November 25, 2020 12:47 PM
  • It was just to eliminate, and with that pair of versions in your respective systems indicates you are both using Office-32 (would get a MISSING reference in Office-64).

    However are you both using the same 32 or 64 bit version of Windows. If not, the MSComCtl.ocx file would be registered in different system folders (system32 v SysWOW64). In theory that shouldn't be a problem but just to know.

    Hmm, just noticed, try changing the following in both systems
    Dim nodX, nodY As Node
    Dim nodX As Node, nodY As Node

    In VBA each variable in the line must be declared individually even if all the same type. In passing also fully declare iChild though not the problem here.

    Also in the NodeCheck event change 
    ByVal Node As MSComctlLib.Node
    ByVal Node As Node

    Wednesday, November 25, 2020 1:30 PM