Returning multiple values from a function

RedSkies

Registered User.
Local time
Today, 17:13
Joined
Aug 17, 2000
Messages
48
I'm relatively new to the coding side of Access any maybe this is a silly question, but how do I return multiple values from a function? Can I return an array? If so, how do I refer to each element in the array that's been returned to the calling subroutine?

For example, if I have a function open a recordset filtered for only one record and I want to return the values in two of the columns in the recordset, how is this done?

Any hints would be appreciated. I'm lost.

Thanks!
 
As a rule functions are not used to return records or recordsets or even values from recordsets. The purpose of a function is to perform an action on some value(s) passed to it. Subroutines are usually used for this purpose. What are you trying to do?
 
Hi,

you can do it one of two ways

1/ make your function return a recordset eg
public function MyRecords(lngWhataver as long...) as recordset
'etc etc
end function
or 2/
use ByRef in the functions arguments list eg if you need to pass in one value to get the record you want and need to pass back two fields then you could do

public function (lngPK as long, ByRef FieldOne as whatever, ByRef FieldTwo as whataver) as boolean

' etc etc
end function
the ByRef means that you are effectively passing the variable itself into the function rather than making a copy of it, as you would if you declared ByVal ( which is the undeclared default setting )
I would agree with Jerry that this ain't pretty, but it's the only way sometimes.

HTH, if it doesn't make sense then post back,

Drew
 

Users who are viewing this thread

Back
Top Bottom