How do I return more than one value from a function?

  • Thread starter Thread starter dchendrickson
  • Start date Start date
D

dchendrickson

I would like some suggestions on returning more than one
value from a function.

I tried creating a custom data type with the elements I
want returned and then creating the function with the 'as
type' part set to my custom type - Access didn't like
that.

I know I could create some global variables and pass the
info that way - I was just looking for something a little
cleaner.

Thanks.
 
Parameters can work as input/output. Supposing you want to pass one
parameter and get 2 back. Example

Function Whatever(x as Long, y as Long, z as Long)

y = x * 10
z = y * 4

End Function

Sub Test()

Dim a As Long
Dim b As Long
Dim c as Long

a = 5

Call Whatever(a,b,c)

Debug.Print a
Debug.Print b
Debug.Print c

End Sub
 
I believe this only works if the Returning function is part of the module
from which it is called ... for example, you can't put the Whatever function
is a Standard Module and call the sub Test from a form ... you get a
"function not defined" error.
 
No....it will work from anywhere as long as the function is public. My
example is public.
 
Paul,

Thanks for setting me straight. Your approach was simple
and works just fine. Scotts approach works well also. Now
I have a couple of new tools for future use. I appreciate
you taking the time to turn a "Oh Sh**" into a "what was
the big deal".

Daen
 
Back
Top