?
Solved

VBA User Defined Types

Posted on 2003-10-23
11
Medium Priority
?
2,493 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
11 Comments
 
LVL 32

Accepted Solution

by:
jadedata earned 500 total points
ID: 9610370
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
ID: 9610400
Need two instances??
Global MbrData1 as MemberData
Global MbrData2 as MemberData

0
 
LVL 4

Expert Comment

by:inox
ID: 9610749

Try to define the UDT public in a MODULE
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 32

Expert Comment

by:jadedata
ID: 9610804
yes, and NOT a class module please.
0
 
LVL 2

Author Comment

by:rthomsen
ID: 9610821
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
 
LVL 4

Expert Comment

by:inox
ID: 9613266

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
ID: 9613643
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
ID: 9614336
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
ID: 9614888
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
ID: 9614980
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
ID: 9615937
thanx for the question rthomsen!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

650 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