I am new to OOP, so probably there is an obvious explaination why this does not work. I am trying to add objects to a collection in VBA. My class module is this:
Option Explicit
'the person class
Public FirstName As String
Public LastName As String
Property Get FullName() As String
'return the person's full name
FullName = FirstName & " " & LastName
End Property
My Code is this:
Sub myProg()
'create a new collection!
Dim Persons As New Collection
Dim p1 As New clsPerson
'give them names in "Loop"
p1.FirstName = "Rita"
p1.LastName = "Smith"
Persons.Add p1
p1.FirstName = "Sue"
p1.LastName = "Jones"
Persons.Add p1
p1.FirstName = "Bob"
p1.LastName = "Brown"
Persons.Add p1
'"Loop" end
For Each p1 In Persons
Debug.Print p1.FullName
Next p1
End Sub
It returns 3 times "Bob Brown". I would like it to return the 3 names I entered.