User-Defined Types and Variants

E

Ed Kopta

I'm trying to write a function with one required parameter and one optional
one, the latter being an array. I've declared the optional parameter as a
Variant, since compile errors compel me to.

The routines that call this function do so with a User-defined Type for the
Variant. But I'm having trouble compiling. When the Type is declared in a
standard module, error messages tell me that only types declared in a
"Public Object Module" can be forced into a variant. When I move the Type
declaration to a Form or Class module, error messages tell me that public
types cannot be declared in an object module. So I guess I'm asking you all
where I can put it!

Thanks for the help.
 
B

Bas Cost Budde

Ed said:
I'm trying to write a function with one required parameter and one optional
one, the latter being an array. I've declared the optional parameter as a
Variant, since compile errors compel me to.

The routines that call this function do so with a User-defined Type for the
Variant. But I'm having trouble compiling. When the Type is declared in a
standard module, error messages tell me that only types declared in a
"Public Object Module" can be forced into a variant. When I move the Type
declaration to a Form or Class module, error messages tell me that public
types cannot be declared in an object module. So I guess I'm asking you all
where I can put it!

I see the problem.

Can you use Classes instead of User Defined Types? that way the
variables will be of type Object, which you can declare in the function
header.

If you've never used classes before, try now. It's fun. And it's easy.

Insert a Class module from the Insert menu. Save it with a name you
like: it will be its type name, used in declarations.

Every public function and sub you define in the class module will become
a method of the class. Remember when you have an object variable, say a
recordset, and you type the dot? IntelliSense displays a list, those are
methods and properties. Methods have this green block symbol.

Every private function becomes invisible for the object user! And,
private is the default for a class. If you don't specify public, it's
private.

You can create properties as well. Maybe you should look into Property
Let in the Help for details. To the user of the object (that is you, in
another function) object properties are more like type members; but to
the class programmer, it is a little extra work with attention.
 
E

Ed Kopta

I guess I'm reluctant to use a Class since these functions will ultimately
reside in a library db, and it's my understanding that those aren't visible
to any other databases. Is this still true (Access XP)?

But were I to do this, I'd need a property for each element, and a global
array for each element, and some sort of Append, Remove and Count methods?
Maybe I'll stick with types and make the function parameter required instead
of optional.

Thanks for the help.
 

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