Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / November 2006

Tip: Looking for answers? Try searching our database.

need result from called function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TMGreen - 18 Nov 2006 16:35 GMT
How do it get the result variable passed back to the original sub from a
called function?  

IE the result of this call function is a variable that is used in the sub

Call EnterSubProjValue

thanks!
Tim Ferguson - 18 Nov 2006 17:44 GMT
> IE the result of this call function is a variable that is used in the sub
>
> Call EnterSubProjValue

 myVar = EnterSubProjValue()

Tim F
TMGreen - 18 Nov 2006 18:08 GMT
I modified the sub code to

subprojresult = entersubproj()

but I am still not getting a result.  in the function I'm setting a value as
follows:
public function
...
subprojvalue = InputBox(message, title, default)
...
end function
the subprojvalue is a global variable and the result is stored at the end of
the function but gone when it comes back to the sum.  any clues as to where
I'm going wrong?

> > IE the result of this call function is a variable that is used in the sub
> >
[quoted text clipped - 3 lines]
>
> Tim F
Rick Brandt - 18 Nov 2006 18:22 GMT
> I modified the sub code to
>
[quoted text clipped - 10 lines]
> end of the function but gone when it comes back to the sum.  any
> clues as to where I'm going wrong?

To make a function return a value then within the function you need to set the
value of the function itself.  If you are instead setting tha value of a global
variable then you need to refer the the golbal variable in youe calling code...

Call entersubproj
subprojresult = GlobalVariableName

...however; returning straight from the function and eliminating the global
variable would be the better way to do it.

Signature

Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt   at   Hunter   dot   com

Granny Spitz - 18 Nov 2006 17:46 GMT
> How do it get the result variable passed back to the original sub from a
> called function?

Use syntax like this.

Public Sub SubroutineA()
   Dim result As Long
   Dim passedParameter As Long

   passedParameter = 100
   result = functionName(passedParameter)
   ' Do whatever with result.
End Sub

Public Function functionName(nParam As Long) As Long
   Dim var As Long

   ' Do calculation on nParam and put the result in var.
   functionName = var
End Function

If there's no parameter to pass, just use empty parentheses after the
function name when calling it and in the definition.
ruralguy - 18 Nov 2006 17:47 GMT
Functions return values and Subs do not.  If it is a function then:
Me.MyValue = EnterSubProjValue
will assign the returned value.

>How do it get the result variable passed back to the original sub from a
>called function?  
[quoted text clipped - 4 lines]
>
>thanks!

Signature

HTH - RuralGuy (RG for short) acXP WinXP Pro
Please post back to this forum so all may benefit.

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.