?
Solved

Problem with user defined Datatype

Posted on 2006-05-30
14
Medium Priority
?
739 Views
Last Modified: 2008-01-09
I have the following in a general declaration of a module

Type tManager
    iIndex As Integer
    strMgrID As String
    strMgrName As String
End Type

and this in the general declaration area of a form
Dim arMgrList() As tManager

when i try to open the form that uses the data type i get a
"user-defined type not defined" error,

if i move the declaration in to the top of the form module i get

"Cannot define a PUBLIC user-defined type within an object module"

ALL mocdules have
Option Compare Database
Option Explicit

at the beginning of all general declarations

been at it for some time cannot see the problem.

TIA
0
Comment
Question by:James Rodgers
  • 4
  • 4
  • 3
  • +2
13 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 16789975
Define it as a public type in a seperate module, not a form module
what happens
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 16790037
as stated above
"user-defined type not defined" error,

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16790041
hang on, just read your first line

"I have the following in a general declaration of a module"

Now was this in a form code module (as you say later on)

"if i move the declaration in to the top of the form module i get"

or a general module? i.e. on database window,

u have Tables/Queries/Forms etc - including Modules. These modules are standalone - not related to forms. If u dont have that, then I suggest u create one, call it Globals or something. You can then add in your general public procedures/functions here

0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 65

Expert Comment

by:rockiroads
ID: 16790055
Yep, I think u got it in a form

Create a new module (if u dont have one already, it will most likely be called Module1)
then add in your type

Public Type tManager
    iIndex As Integer
    strMgrID As String
    strMgrName As String
End Type


Now in form code u can use it
e.g.
Dim x As tManager
0
 
LVL 77

Accepted Solution

by:
peter57r earned 1200 total points
ID: 16790090
Hi Jester_48,
It all looks quite OK to me.
Your initial approach is correct and I can't see why you should be having a problem.

So it's all a bit clutching at straws.
There is no duplicate name involved?  
I take it the app compiles without error?

Pete
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 16790106
no i had it in a stand a one module

Option Compare Database
Option Explicit

Public Type tManager
    iIndex As Integer
    strMgrID As String
    strMgrName As String
End Type

everything in that module, this is it, nothing else

i get the "user-defined type not defined" error

if i move it into a form module - only one form in the DB - i get "Cannot define a PUBLIC user-defined type within an object module"

i had done everthing you suggested prior to posting, couldn't figure out why the declaration was not working so i posted here
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 16790162
>>So it's all a bit clutching at straws.
i know - coming here 'cause i'm tapped out, error makes no sense

>>There is no duplicate name involved?
no if there was a duplicate it would be an "ambiguous declaration" error ( or something like that)

>>I take it the app compiles without error?
how do you compile an access module?
0
 
LVL 17

Assisted Solution

by:Natchiket
Natchiket earned 800 total points
ID: 16790199
in the vba devlopment environment menubar select debug, compile
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 16790267
in the Form module, change from Public to Private:


Private Type tManager
    iIndex As Integer
    strMgrID As String
    strMgrName As String
End Type

AW
0
 
LVL 65

Expert Comment

by:rockiroads
ID: 16790302
when u do a debug/compile, where does it fall over

user-defined type not defined

perhaps u have made a mistake when defining a variable and not using tManager spelt right?
0
 
LVL 25

Author Comment

by:James Rodgers
ID: 16790306
thanks Natchiket,
using the compile identified the true error, it was not my user defined type but teh declaaration of a database that was causing the error indicating an incorrect or missing reference.

sorry, but i am going to have CS reopen and split teh points between Natchiket and peter57r as he originally suggested the compile.

Jester_48
0
 
LVL 17

Expert Comment

by:Natchiket
ID: 16790320
woah ... looks like I've been over credited ... are you sure the other contributors didn't help as well ?  You can split points you know.
0
 
LVL 17

Expert Comment

by:Natchiket
ID: 16790343
ok
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question