Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function

Status
Not open for further replies.

patweb

Programmer
Apr 17, 2003
174
BE
hi, I am still confused about a function : how to pass a value and how to get the result of a number of action (e.g. calculation) on this value out of the function.

Dim strpagid As String
valuetosendtothefunction = rst1![PAG-ID]

functioninclude (valuetosendtothefunction)
calculation.....
end function

strpage = functioninclude(valueigetofthefunction) & rst1![text]

can someone clear this out for me and correct the above description, so it became clear to me for ones and forever.

thanks, pat

 
Function functioninclude(nameofparameter)
calculation.....
functioninclude = ResultOfCalculation
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
pat

Here is a real life example...

Code:
Function [COLOR=blue]FindTotalTime[/color]([COLOR=green]lngID As Long[/color]) [COLOR=blue]As Integer[/color]

Dim dbs As DAO.Database, rst As DAO.Recordset
Dim strSQL As String

strSQL = "SELECT Sum(TimeSpent) as TotalTime FROM tblHistory " _
& "WHERE CallID = " & [COLOR=green]lngID[/color]

Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset(strSQL)

rst.MoveLast[COLOR=blue]
FindTotalTime = Nz(rst!TotalTime, 0)[/color]

rst.Close
dbs.Close
Set rst = Nothing
Set dbs = Nothing

End Function

See how lngID is passed to the function. It can be called from a form, and SQL statement, a report or even from another module.

For example...
SELECT ContactName, FindTotalTime(CallID) ....

On a form
=FindTotalTime([CallID])

In the function, the passed variable or variables is / are defined as is the returned value in the function declaration statement.

The returned value is assigned to the name of the function as expressed by PHV.

This is a pretty simple example. You can pass more than one value, and use the Optional variables. But only one value is returned.

See Access Help for more info
Richard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top