Solved

VBA User Defined Types

Posted on 2003-10-23
11
2,473 Views
Last Modified: 2007-12-19
I'm developing a system in Access 97.  I have some user defined types declared publically and used in several form code modules.  I would like to be able to pass an instance of these types between forms but if I try and declare a public function in a form object module with the UDT as a parameter I get a compile error.  Does anyone know the best way to pass objects between forms?

Thanks

rthomsen
0
Comment
Question by:rthomsen
  • 6
  • 3
  • 2
11 Comments
 
LVL 32

Accepted Solution

by:
jadedata earned 125 total points
Comment Utility
Hey rthomsen!

 Heres what I do

 Type MemberData
  .Name as String(25)
  .Age as Integer
  .Tele as string(14)
 end Type
 Global MbrData as MemberData

Now I can pass around the MbrData variable (it's just an array after all)
anywhere within the confines of the application.


regards
Jack
0
 
LVL 32

Expert Comment

by:jadedata
Comment Utility
Need two instances??
Global MbrData1 as MemberData
Global MbrData2 as MemberData

0
 
LVL 4

Expert Comment

by:inox
Comment Utility

Try to define the UDT public in a MODULE
0
 
LVL 32

Expert Comment

by:jadedata
Comment Utility
yes, and NOT a class module please.
0
 
LVL 2

Author Comment

by:rthomsen
Comment Utility
The UDT's are defined in a module but VBA won't let you pass them from form module to form module using public functions or subroutines.  I was hoping for something a little more elegant than global variables but I guess sometimes you just have to use the "brute force" method.  I will try and play around with a globals and see if I can get it to work.  If no one else comes up with any ideas I will award Jack the points.

Thanks for your help guys.

rthomsen
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 4

Expert Comment

by:inox
Comment Utility

I can't reproduce your problem. I have

MODULE module1:

Public Type t1
  I As Integer
End Type

form2:
Sub Xt1(ByRef d As T1)
Dim I
  I = d.I
End Sub


form1:
Dim d As T1
  ..
  d.I = 1
  Call Form_Form2.x2(d)
  ..

and this works.

PS:
don't forget: call SUBs with a preceeding Call statement or ommit the parentheses
0
 
LVL 32

Expert Comment

by:jadedata
Comment Utility
I still can't figure out why some developers consider the proper use of a global variable inelegant..
0
 
LVL 2

Author Comment

by:rthomsen
Comment Utility
Inox - What version of Access are you using?  I get the error: "User-defined types and fixed-length strings not allowed as the type of a Public member of an object module; Private object modules not allowed as the type of a public member of a public object modules" when I try to compile.  Also why is your sub call not the same as your definition

Sub Xt1(ByRef d As T1)

Call Form_Form2.x2(d)

Jadedata - I agree, I've never really seen a huge problem with global variables but I've always been told that they're bad programming practice so I try and avoid using them.
0
 
LVL 4

Expert Comment

by:inox
Comment Utility
rthomsen,
I work with Acc2000 and I remember there were some differences on UDT's, so I'll check it later.

PS:
Call Form_Form2.x2(d) is nonsense, must be
Call Form_Form2.Xt1(d) of course (just copied te wrong line)
0
 
LVL 32

Expert Comment

by:jadedata
Comment Utility
Bad programming practice is having things not work or take too long to develop because you refuse to use "inelegant" code. (IMHO)
0
 
LVL 32

Expert Comment

by:jadedata
Comment Utility
thanx for the question rthomsen!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now