Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2009
    Posts
    185

    Question Unanswered: Can a fuction return more than one value.

    Can a function return more than one value? I use global variables now but I don't like using global variables. I call the function get the value to a local variable from the global variable then clear the global variable.

    Can I pass two or three variables to a function?


    This is access with vba code.

  2. #2
    Join Date
    Jul 2009
    Posts
    185

    Question Select return one to many records.

    In correct thread. sorry
    Last edited by Bob2119; 07-23-09 at 18:22.

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    change the scope of the parameters int he function
    change from ByVal to ByRef

    eg
    public function Myfunction(ByRef Param1 as datatype, ByRef Param2 as datatype)

    by ref means pass the value as a reference to that value in the calling module any changes made to variables in the function are made to the variables in the calling module. effectively any variable referenced by ByRef is a common variable withint he scope of the calling module.
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    Jul 2009
    Posts
    185

    Thumbs up

    I'll give that a try, it looks like what I am looking for.

    Thank much.

  5. #5
    Join Date
    Jul 2009
    Posts
    185
    I was reading the help it is as clear as mud.
    Is datatype string or integer etc.
    Public Function isfunction(ByRef date as date,ByRef sMode as string)
    Does that look right?

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    datatype is what ever datatype you want that column to be
    eg
    public MyFunction(aDate as date, aName as string, anInteger as Integer, aDecimaNumber as double, aBooleanvalue as Boolean.... and so on

    in vba you don't 'have' to specify the datatype, if you dont' VBA defautls to variant which will handle any datatype but that coems at a performance cost which may not be noticable for your app and it aslo increases the chnaces of subtle errors creeping in with incorrect datatypes being passed to functions. mind you variant can also handle NULLS better than the string datatype
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Jul 2009
    Posts
    185

    Question

    You didn't use ByRef in your example is it the default

  8. #8
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Yes, your example looks fine. Healdem was merely offering you some additional information about datatypes.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •