Solved

VBA User Defined Types

Posted on 2003-10-23
11
2,479 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
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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

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