Global Declaration of Class Module for Use by other Code Objects

R

RalphInBoise

Hello to all,

In the code handler for my form object’s button click event, I want to
use a subroutine from a class module. But when I go to declare it for
use in the (General) section of the new code object's (Declarations),
somehow, the VBA Editor seems to think that I want to redefine that
existing subroutine in the new code object's namespace.



The desired subroutine is perfect, and I do NOT want to re-define it, so
how do I declare it for use?



And without a declaration, my compiler keeps giving me a message box
saying, "Sub or Function not defined” when I use the keyword, “Call”
prior to the sub’s name. Or without a declaration and using just the
sub’s name without the keyword, “Call”, a message box saying, “Compiler
error: Syntax error”.



Any help would be appreciated.



TIA,

Ralph in Boise
 
D

Dan Artuso

Hi,
Do you really mean it's in a class module as opposed to a standard one?
If it's a class, you have to instantiate the class, then use it's methods/properties.

It's more likely you mean a function in a standard module, in which case you
simply declare it public:

Public Sub yourSub()

End Sub

Now you can simply use it:

yourSub

if it requires arguments then:
yourSub yourArg
 
A

Albert D. Kallal

RalphInBoise said:
Hello to all,

In the code handler for my form object’s button click event, I want to
use a subroutine from a class module. But when I go to declare it for
use in the (General) section of the new code object's (Declarations),
somehow, the VBA Editor seems to think that I want to redefine that
existing subroutine in the new code object's namespace.



The desired subroutine is perfect

No, it is not perfect, since it does not work at all.
and I do NOT want to re-define it, so
how do I declare it for use?

You got about 8 or 9 responses to both your emails. Time to stop, and take
break here. The concepts and ideas of programming in access are obviously
new to you. While learning this programming stuff can be very difficult, it
is not really that hard either.

Why are you trying to use a class module here? For what reason? When you
create a form, or a class module in ms-access, you are in fact creating a
class object. However, in your case I see no reason to be using, or trying
to use a class module. Simply cut and paste your code out of the class
module, and place it into a regular module.

You can call the base instance of the object, but that really a bad idea.
So, you *can* go:

Call Class1.YouSubName


You got quite a few responses telling you move the code out of the class
module, and place it into a regular module. Either you are being stubborn,
or you are not reading the responses, or you are not understanding the
responses.

If do want some ideas as to WHEN to use a class module, you can read the
following article of mine:

http://www.attcanada.net/~kallal.msn/Articles/WhyClass.html
 

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