Solved

VBA User Defined Types

Posted on 2003-10-23
11
2,489 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 125 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
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 …
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…

690 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