Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"User-defined type not defined" Error

Status
Not open for further replies.

Trevahaha

Programmer
Nov 21, 2002
129
US
Okay -

So you'd think this be about DAO vs ADO -- but I'm only using ADO and always declare Dim rst as ADODB.recordset

Anyways... I am making a user-defined type "CurrentIDs" which I have in a Class Module:

Public ServiceID as Long
...
Public ActivityID as Long

then in a Module "Utilities" I declare this globally:

Global Current as New CurrentIDS


When I attempt to compile, it gives me the User-defined type not defined... but it doesn't show a line or anything that the error occurs... would it normally with this error?

Maybe it's really unrelated to the whole global user-defined type.. but I'm really clueless at this point.


THANKS!

Trevor
 
I do not see where you have defined "CurrentIDS" either.


rollie@bwsys.net
 
First, you've got a terminology problem here--and boy, did it throw me for a loop! It took me a while to figure out what you were getting at.

A "User defined type" (UDT) is not a Class module. It's defined with the Type keyword, and it contains only data. For example:
Public Type PersonalInfo
Name As String
BirthDate As Date
SSN As String*9
etc.
End Type
You can then declare variables of this type:
Dim pi As PersonalInfo
And refer to their "member" variables:
txtName = pi.Name
txtBirthDate = pi.BirthDate

This "dotted" syntax looks similar to the syntax you use to refer to properties of an object, but a UDT is very different from an object class. If you know C or C++, a UDT is similar to a struct.

A Class module, on the other hand, can contain not only data but code (methods). You can declare variables of the class's type (called "object variables"), but unlike a UDT the variables won't actually refer to anything until you execute an assignment statement. (Object variables are initialized to Nothing.)

The tradeoffs are: (1) UDTs are a collection of bits of related data; Classes are used to make objects that encapsulate both data and behavior (code). (2) UDTs are just about as efficient to use as ordinary variables; Classes have a pretty fair amount of overhead. (3) UDTs are simple to design; Classes take more thought, if they're designed right.

So first you should decide whether what you really want is a UDT or a Class. My guess is that you only need a UDT, but maybe you're trying to learn how to use Class modules and application requirements aren't really an issue.

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Hmm -- good point. Okay, so yes, I'm using a class module. I guess I was building this to be like a class in C++ and less like a struct. I have a sub function of the CurrentIDs -- just a simple reset function that could be handled elsewhere. Do you think the error is resulting from this? I'd rather not change it to a UDT since it's been working so great so far.. I guess the issue is to find the error. Everything in the project works, I just can't "compile" -- which would be nice if I ever wanted to make a mde file.

Anyways, Thanks for the lesson on class vs UDT.. and the C perspective on it, it actually did clear up the difference a lot more! :)

Trevor
 
Now that I know you're familiar with C++ I'll kick it up a technical notch and be less pedantic.

The class isn't a UDT, so it's doubtful that the message refers to something to do with your class.

The little bit of code you showed is correct usage for a Class, except that Global is a hangover from Access Basic (in Access v.1 and .2). It has been retired it in favor of Public, which means the same thing. It still compiles in Access 97, but is undocumented. Try switching it to Public and see if the problem goes away.

Other than that, I don't have a clue. I've seen this error message before, but I couldn't find it in the Help file.

Was there a time you didn't get this message? Could you back out your code changes to find out when the message was introduced? Then at least would narrow down what we have to look at. What version of Access are you using?

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
I'm using Access 2002. This database is actually quite large -- and many many changes have occured since I last can remember not getting the error. I wish the debugger was a little better in stating where it's having the problem. <ugh>

I went and changed all my global variables to Public... no help.

Anywhere I've seen this error online, it's regarding unexplicit DAO use. The help file states that it's that or using a UDT as private vs public.. etc.
 
Without seeing your code, it's difficult to be specific, but I think the error is related to a piece of code using the DOT

eg MyClass.Something or MyUDT.something

and Access has no idea what MyClass or MyUDT is - so it assumes it is a UDT that isn't defined.

Can you not run interperted, with a breakpoint, and see where the error arises?
 
My apologies, for my last stupid post, I didn't read carefully enough - I see it runs fine when not compiled.

 
Well, it brings up a good point.. maybe there's a better way for me to debug. When I just go up a click on the compile from the menu, the error message pops up, but no line is selected. Is there a way I can go around this and see where it's having problems?
 
I vaguely remember something about an option somewhere that specifies whether to track breakpoints into add-in libraries. Or maybe it's to allow display of source code in library databases. Could it be that the error is occurring in a library, and this option is turned off, so no line is displayed? (Does this option even exist? I don't have A2K2, so I can't look for myself.)

Rick Sprague
Want the best answers? See faq181-2886
To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top