Working With Class Modules

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am working with class modules and have dedicated several to particular
tables in this DB project. I am calling some of the functions within the
class objects directly without creating a new instance of the class. I am a
beginner when it comes to working with class modules.

Here is an example. I have a class module called class_stores. In this
module I have a function: DBLookUpStoreID(sStoreName as String) as Long.

I will call on this function from forms or other modules to look up the
store ID for a particular store name (i.e. lStoreID =
class_stores.DBLookUpStoreID("Giant")).

Question: Is this acceptable, or is it necessary to create a new instance of
the class each time I want to access a function?
 
Devlin said:
I am working with class modules and have dedicated several to particular
tables in this DB project. I am calling some of the functions within the
class objects directly without creating a new instance of the class. I am a
beginner when it comes to working with class modules.

Here is an example. I have a class module called class_stores. In this
module I have a function: DBLookUpStoreID(sStoreName as String) as Long.

I will call on this function from forms or other modules to look up the
store ID for a particular store name (i.e. lStoreID =
class_stores.DBLookUpStoreID("Giant")).

Question: Is this acceptable, or is it necessary to create a new instance of
the class each time I want to access a function?

If I were you I would put the function in a regular module. You can always
call it from within a class module whenever you need to.
 
Devlin said:
I am working with class modules and have dedicated several to
particular tables in this DB project. I am calling some of the
functions within the class objects directly without creating a new
instance of the class. I am a beginner when it comes to working with
class modules.

Here is an example. I have a class module called class_stores. In
this module I have a function: DBLookUpStoreID(sStoreName as String)
as Long.

I will call on this function from forms or other modules to look up
the store ID for a particular store name (i.e. lStoreID =
class_stores.DBLookUpStoreID("Giant")).

Question: Is this acceptable, or is it necessary to create a new
instance of the class each time I want to access a function?

I'm a little puzzled. I wouldn't expect you to be able to call a member
function of the class object unless you had created an instance of the
object, and qualified the call with a reference of that instance. Are
you saying you can call the member function without ever creating an
instance? Or are you just asking whether it's okay to create just one
instance and use it over and over again? If the latter, there's nothing
wrong with that at all, so long as it makes sense within the context of
your application's logic.

One thing you should be sure to do, though, is destroy the instance of
the class object when you really are done with it. If you're having
problems with Access not closing, it's conceivable that an undestroyed
instance of a class object is the reason.
 
I know I should know how to do this, but how do you call a procedure in a
standard module from a class? I've done it before but my mind has gone
blank, and I must be typing the wrong queries into office help!
 
You call it the same way you call any of the built-in VB functions or
methods.
 
Which is? I know I sound like an idiot but what I have been doing isn't
working in this case, so obviously something is wrong and if I have to redo
everything...! Can you give an example? Say the standard module is a, the
function I want to call dog. Within the class module, what exactly would I
type? Simply typing "dog" or dog(a) or a(dog) or assigning
variables....isn't working.
 
For a function, you have to assign it to a variable:

x = Dog()

As to your original question, ("is it necessary to create a new instance of
the class each time I want to access a function?"), it all depends on what
the function is doing. You'll have to give more details to get a more
specific answer, I'm afraid.
 
Tarnia said:
Which is? I know I sound like an idiot but what I have been doing
isn't working in this case, so obviously something is wrong and if I
have to redo everything...! Can you give an example? Say the
standard module is a, the function I want to call dog. Within the
class module, what exactly would I type? Simply typing "dog" or
dog(a) or a(dog) or assigning variables....isn't working.

Either...

dog

....or...

call dog

should work.
 
I'm afraid I was taking advantage of someone else's post, since I had a
similar problem. I hope that's ok. Thank you for your help...it seems I was
defining the variable incorrectly!
 

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

Back
Top