Passing values from a function to a form.

R

rich

Ok, creating an invoice calculator. I have made a public
function to do all the calculations, the code is written
and all the values calculated come back correct (I have
checked this by inserting msgbox's in different places).
I would lke to know how to get the calculated values to
return to fields in a form where the user will activating
the event that calls the function. I have used send
object to populate reports in an e-mail, and was wondering
if it was something similar to this. Thank you in
advance, Rich
 
G

Graham R Seach

Rich,

If your function only returns a single value, then the following syntax will
work:
Me.txtMyTextBox = MyFunction()

If your function calculates multiple values that you want returned, you have
two options:

1. In the function declaration, add parameters that will contain the values
you want returned. For example:
Public Function MyFunction(Input_1 As Currency, Input_2 As Integer, _
Output_1 As Currency, Output_2 As Integer) As Boolean
'- - -
End Function

You'll need to call the function using variables which will contain the
results of the function to be used in the calling procedure, for example:
Dim curInput_1 As Currency, curOutput_1 As Currency
Dim intInput_2 As Integer, intOutput_2 As Integer

curInput_1 = 12.95
intInput_2 = 123

If MyFunction(curInput_1, intInput_2, curOutput_1, intOutput_2) =
True Then
'Calculation succeeded
Me.txtMyTextbox1 = curOutput_1
Me.txtMyTextBox2 - intOutput_2
End If

2. You can turn your function into a class module, and use properties to
return its values. We can help you with this if you supply a tad more
information about what your function does.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Top