Set Errors

R

Ray Pixley

I keep getting run time error 91, "object variable with block variable not
set" when doing the following:

First, create a Class Module called "CPM" whose content is

Option Explicit
Public Name as Collection

The code I'm trying to run is:

Option Explicit
Dim D As Collection
Dim C As CPM
Sub test()
Set C = New CPM
Set D = New Collection
D.Add "aa", "1"
subB
C.Name.Add "ss", "1" ' <----------------run time error
subA
End Sub
Sub subA()
C.Name.Add "tt", "2" ' <-------------- also want this to work
End Sub
Sub subB()
D.Add "bb", "3"
End Sub

I can add data to D object, but the C object constantly reports that run
time error. But the message makes no sense.

(My intent is to add a lot more public collections to CPM, and minimize the
amount of redundant coding that I have to do.)
 
T

Tim

You do not initialize the collection in the class - you only declare its
type.

Try this in the class_initialize code:

Set Name = new Collection

or just use

Public Name as New Collection


Tim
 
R

Ray Pixley

It worked as long as

Public Name as New Collection

is placed in the class' declaration section.

Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top