Problem using "Type" in VBA

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

Guest

When I use a "Type" statement in VBA's class module, I get an error. Is
there any way to get around this problem?

Thanks,

Eddie
 
"Eddie's Bakery and Cafe'" <Eddie's Bakery and
Cafe'@discussions.microsoft.com> wrote in message
When I use a "Type" statement in VBA's class module, I get an error.
Is there any way to get around this problem?

Thanks,

Eddie

Where are you using the statement? What error are you getting? The
Type statement can only be used at module level, but aside from that I
don't see why you might have a problem.
 
Hi Dirk,

Thanks for taking my question. I am new to MS Access (first time
user/developer) and I am developing most of the application in Visual Basic.
I have been having several problems. This is just one of many. Below is a
code snippit that mimics the problem.

I defined an object in the Class Module that looks simular to this: The
file name is clsType

-----------
Option Compare Database
Option Explicit

Public Type myType
a As Integer
End Type
-----------------------------
I defined a global variable referencing this object in the MS Access Class
Object Section: Form_ myForm. The variable is defined in the Declaration
Section of the Form_myForm object (For Exampel: DIM g as clsType).

Afer the global declaration section, I have the "Private Sub Form_Load()"
routine where I created a reference variable using the new statement: (g =
new clsType).

When I save the file and run the form I get the following error:
"The Expression ON LOAD you entered as an Event Property Setting Created
the Following Error: Cannot define a public user-defined type within an
object module ..."

Any help is greatly appricated,

Thanks,

Eddie
 
Eddie,
instead of UDF in class modules you can use simple classes

make a class myType

with one property
Public a As Integer

and use it instead of UD type
 
Public user-defined types can only be defined in standard modules, Eddie,
not in class modules (which includes form and report modules).
 
Back
Top