SOLVED

VBA: Compiler error: Method or Data member not found

%3CLINGO-SUB%20id%3D%22lingo-sub-3198400%22%20slang%3D%22en-US%22%3EVBA%3A%20Compiler%20error%3A%20Method%20or%20Data%20member%20not%20found%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3198400%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20trying%20to%20implement%20a%20doubly%20linked%20list.%20I%20have%20two%20class%20modules%2C%20one%20for%20each%20node%20and%20one%20for%20the%20linked%20list.%3C%2FP%3E%3CP%3ENode%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3EOption%20Explicit%0A%0APrivate%20Value%20As%20Long%0APrivate%20prevNode%20As%20Node%0APrivate%20nextNode%20As%20Node%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELinked%20List%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3EOption%20Explicit%0A%0APrivate%20head%20As%20Node%0A%0APublic%20Sub%20Add(inputValue%20As%20Long)%0A%0A%20%20%20%20Dim%20newNode%20As%20Node%0A%20%20%20%20Set%20newNode%20%3D%20New%20Node%0A%20%20%20%20%0A%20%20%20%20newNode.Value%20%3D%20inputValue%0A%20%20%20%20%0A%20%20%20%20Set%20newNode.nextNode%20%3D%20head%0A%20%20%20%20Set%20head%20%3D%20newNode%0A%20%20%20%20%0A%20%20%20%20%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20then%20trying%20to%20test%20the%20code%20by%20making%20a%20test%20module%20which%20just%20adds%20some%20nodes%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-visual-basic%22%3E%3CCODE%3EOption%20Explicit%0A%0ASub%20Test()%0A%0A%20%20%20%20Dim%20linkedList%20As%20New%20linkedList%0A%20%20%20%20linkedList.Add%20(1)%0A%20%20%20%20linkedList.Add%20(2)%0A%20%20%20%20linkedList.Add%20(3)%0A%20%20%20%20linkedList.Add%20(4)%0A%20%20%20%20%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20is%20saying%20the%20that%20%22newNode.Value%20%3D%20inputValue%22%20line%20throws%20the%20error.%20Why%20is%20this%20happening%20as%20the%20Value%20attribute%20is%20in%20the%20Node%20class%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3198400%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3198494%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%3A%20Compiler%20error%3A%20Method%20or%20Data%20member%20not%20found%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3198494%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1314469%22%20target%3D%22_blank%22%3E%40FergO18%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20declared%20the%20three%20properties%20if%20Node%20as%20Private%2C%20so%20they%20are%20not%20visible%20to%20other%20modules.%3C%2FP%3E%0A%3CP%3EEither%20declare%20them%20as%20Public%2C%20or%20create%20Get%2FLet%2FSet%20methods%20for%20them.%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

I am trying to implement a doubly linked list. I have two class modules, one for each node and one for the linked list.

Node:

 

Option Explicit

Private Value As Long
Private prevNode As Node
Private nextNode As Node

 

 

Linked List:

 

Option Explicit

Private head As Node

Public Sub Add(inputValue As Long)

    Dim newNode As Node
    Set newNode = New Node
    
    newNode.Value = inputValue
    
    Set newNode.nextNode = head
    Set head = newNode
    
    
End Sub

 

 

I am then trying to test the code by making a test module which just adds some nodes:

 

Option Explicit

Sub Test()

    Dim linkedList As New linkedList
    linkedList.Add (1)
    linkedList.Add (2)
    linkedList.Add (3)
    linkedList.Add (4)
    
End Sub

 

It is saying the that "newNode.Value = inputValue" line throws the error. Why is this happening as the Value attribute is in the Node class?

2 Replies
best response confirmed by FergO18 (New Contributor)
Solution
I have found my own mistake. I had set the attributes of the nodes to be private, meaning that the test module couldn't access them. Changing those to be public from private has fixed my issue.

@FergO18 

You declared the three properties if Node as Private, so they are not visible to other modules.

Either declare them as Public, or create Get/Let/Set methods for them.