Instead of using an array consider creating your own variable type:
VBA (Access 95 onwards) allows you to return an entire structure of values.
In database terms, this is analogous to returning an entire record rather
than a single field. For example, imagine an accounting database that needs
to summarize income by the categories Wages, Dividends, and Other. VBA
allows you to declare a user-defined type to handle this structure:
Public Type Income
Wages As Currency
Dividends As Currency
Other As Currency
Total As Currency
End TypeYou can now use this structure as the return type for a
function. In a real situation, the function would look up your database
tables to get the values, but the return values would be assigned like this:
Function GetIncome() As Income
GetIncome.Wages = 950
GetIncome.Dividends = 570
GetIncome.Other = 52
GetIncome.Total = GetIncome.Wages + GetIncome.Dividends +
GetIncome.Other
End FunctionTo use the function, you could type into the Immediate
Window:
? GetIncome().Wagesor you could include a text box on a report and set
its ControlSource property to:
= GetIncome().Total(Note: the use of "Public" in the Type declaration
gives it sufficient scope.)
Programmers with a background in C will instantly recognize the
possibilities now that user-defined types can be returned from functions. If
you're keen, user-defined types can even be based on other user-defined
types.