Help returning a value from a module to a form

M

Marty Newbe

Hi can someone tell me what I am doing wrong.
I am calling a function from within a form. The function is located in
module2.
The values pass to the function fine but the returned value from test2 is
alway 0.
Its probably a fundamental mistake but any help would be appreciated.

Option Compare Database
'Form
Option Explicit
Public Sub get_lib_num_Click()
Dim a, b, z As Integer
a = 5
b = 3
z = test2(a, b)
End Sub

'module2
Option Compare Database
Option Explicit

Public Function test2(ByVal x As Integer, ByVal y As Integer) As Integer
z = x + y

End Function
 
D

Duane Hookom

Try:
Public Sub get_lib_num_Click()
Dim a As Integer, b As Integer, z As Integer
a = 5
b = 3
z = test2(a, b)
End Sub

'module2
Option Compare Database
Option Explicit

Public Function test2(ByVal x As Integer, ByVal y As Integer) As Integer
test2 = x + y
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top