variable not appearing in report

M

Marc Miller

I have a function in a module and call it from a text field in
a report, yet I keep getting a value of 0 for the variable.

I tried it on a real production report in Access 2000 and then I created a
test
in Access 2003. Both have the same behavior. Here is what I have


Module -

Public myVar as integer

Public function getNum() as integer

myVar = 55
End Function


In the report I have a text field that contains:

=getNum()

It returns 0.

Any help would be quite appreciated.

Thanks,
Marc Miller
 
J

John Spencer

You have to assign the value to the function in order to return it

Public function getNum() as integer

myVar = 55
GetNum = myVar

'As simple as this is you could just use
' GetNum = 55

End Function
 
M

Marshall Barton

Marc said:
I have a function in a module and call it from a text field in
a report, yet I keep getting a value of 0 for the variable.

I tried it on a real production report in Access 2000 and then I created a
test
in Access 2003. Both have the same behavior. Here is what I have

Module -

Public myVar as integer

Public function getNum() as integer

myVar = 55
End Function


In the report I have a text field that contains:

=getNum()

It returns 0.


You must use the function's name to return its value:

Public function getNum() as integer

myVar = 55
getNum = myVar

End Function
 
M

Marc Miller

Gentlemen,

Thank you! Life is much better now. MSAccess never ceases to amaze me.

Regards,
Marc Miller
 

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