Wednesday, February 18, 2009

Multi-Value returns in Access

There are times when you write a function and want to return more than one value. Using VBA in Access you can declare a user defined type that has multiple types within its structure.

Public Type UserType1
Fld1 as integer
Fld2 as string
Fld3 as date
End Type

Function TestAType() as UserType1
TestAType.Fld1 = 1
TestAType.Fld2 = "This is field 2"
TestAType.Fld3 = #2/1/2009#
End Function

You can then reference the value you need in another part of the program.

MyIntegerValue = TestAType().Fld1