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

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.
 
P

Paul Overway

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
 
S

Scott McDaniel

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.
 
P

Paul Overway

No....it will work from anywhere as long as the function is public. My
example is public.
 
D

dhendrickson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top