Form.Variables Collection? (1 Viewer)

evanscamman

Registered User.
Local time
Today, 08:04
Joined
Feb 25, 2007
Messages
274
Is there any way to refer to a variable in a Form without literally spelling out its name - through a collection perhaps?

For example:

I am using a class module to handle multiple instances of a subform in the same form.

Code:
Public basIF As New basItemFind         '1st Instance for sfrmPurchaseOrderQueue
Public basIF2 As New basItemFind        '2nd Instance for sfrmPurchaseOrderItem

From a control in the subform I need to call a Function in the class module:

Code:
Parent.basIF.IF_LostFocus

The subform is peppered with similar calls to the class module - but, of course, the calls only reference the first instance of the subform.

Without duplicating tons of code, I need a simple way to alternately refer to basIF or basIF2. Something like this:

Code:
strClassName = "basIF2"
Parent.Variables(strClassName).IF_LostFocus

Of course, this doesn't work, but I'm hoping there is a way to do this without nasty code duplication. I don't think an array will do it either...

Any ideas? Is this possible?

Thank you,
Evan
 

MarkK

bit cruncher
Local time
Today, 08:04
Joined
Mar 17, 2004
Messages
8,181
Check out a VBA.Collection. It can contain different types of objects and when you add an object you can provide a key to use to reference that object.
Code:
dim c as new vba.collection

[COLOR="Green"]'add items to the collection[/COLOR]
c.add object1, "obj1"
c.add object2, "obj2"
c.add otherobject, "oobj"

[COLOR="Green"]'reference a member of an object in the collection[/COLOR]
debug.print c.item("obj2").memberOfObject2
 

evanscamman

Registered User.
Local time
Today, 08:04
Joined
Feb 25, 2007
Messages
274
Thank you, Lagbolt! Exactly what I needed - works perfectly. :)
 

Users who are viewing this thread

Top Bottom