Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBA User Defined Types

Posted on 2003-10-23
11
Medium Priority
?
2,494 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 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 is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

810 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