Using Class Module

R

Roy Goldhammer

Hello there

I have class module that i run it from some module

In the class module i opened form

Now i need that after i do something on the form i can set data from the
form into the class module

How can i do that?

--
øåòé âåìãäîø
ù.î. òúéã äðãñú úåëðä
(e-mail address removed)
èì: 03-5611606
ôìà' 050-7709399
 
J

John Nurick

Hello there

I have class module that i run it from some module

In the class module i opened form

Now i need that after i do something on the form i can set data from the
form into the class module

How can i do that?

You can't "set data" in a class module. A class module is like a
template or definition, and you have to create an instance of the class
(an object) before you can do anything with it. In fact it's just like
working with the standard Access and VBA objects:

Dim objMyClass As MyClass

Set objMyClass = New MyClass

With objMyClass
...
End With
 
R

Roy Goldhammer

Whell John

I found Hard way to do this:

1. declaring the class module also inside of the form
2. After i do openForm i set the form local variable to the class module
SET Forms!frmName!cls = me
And it works fine.

But the problem is not what after i'm using debug and stop some procedure
the cls Does not provide the data.

What can i do?
--
???? ???????
?.?. ???? ????? ?????
(e-mail address removed)
??: 03-5611606
???' 050-7709399
 
J

John Nurick

Roy, I'm not looking over your shoulder, and I don't know either what
you're trying to achieve or what the class you've create represents.
You'll have to explain much more clearly if anyone here is to be able to
help.
 
R

Roy Goldhammer

Whell John

I have some complex structurs that it is very hard to manage them on
runtime.

The best way i could see that works is by using Object oriented.

For this i'm using class module who do anything, keeps data inside.

And for achive this i need that every form i'm run from it can reach it and
get information from it or even update the class module

Like ActiveX dll works, that have main class module who runs everything
Is there a way to do this?
 
J

John Nurick

Roy,

You need to distinguish between a class module, which contains the VBA
code that defines the class, and the instances of the class that are
created by code running elsewhere in the application.

From what you say, it sounds as if a global Collection is what you need.
Declare it n a code module (not a form or class module):

Public gcolMyObjects As Collection

Then, in code behind a form (or in a code module), you can do something
like this:

Dim oMyClass As MyClass
Dim strKey As String
...
Set oMyClass = New MyClass
With oMyClass
'set properties etc.
End With

'if desired, create a key value for the object
strKey = "blah_blah" 'maybe give this the same
'value as oMyClass's Name
'or ID property if it has one?
'add it to the collection
gcolMyObjects.Add oMyClass, strKey

'maybe store strKey in a table or somewhere so it can
'easily be found later

'release the variable
Set oMyClass = Nothing

You now have the globally-accessible Collection containing the object.
You can repeat as desired to add more objects to the Collection, and you
can access them from anywhere in the application like this:

gcolMyObjects("blah_blah")
or
gColMyObjects(1)



Whell John

I have some complex structurs that it is very hard to manage them on
runtime.

The best way i could see that works is by using Object oriented.

For this i'm using class module who do anything, keeps data inside.

And for achive this i need that every form i'm run from it can reach it and
get information from it or even update the class module

Like ActiveX dll works, that have main class module who runs everything
Is there a way to do this?
 

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

Similar Threads


Top