How get global variable into report textbox ?

M

mscertified

I've been trying to do this for 2 hours and am completely stuck.
I can display the variable with Msgbox but as soon as I try to set the text
box to the variable, I get an error (can't assign to this object)? It also
failed when I try to do it via the 'controlsource' Why is this simple
opertion so difficult?
 
M

Marshall Barton

mscertified said:
I've been trying to do this for 2 hours and am completely stuck.
I can display the variable with Msgbox but as soon as I try to set the text
box to the variable, I get an error (can't assign to this object)? It also
failed when I try to do it via the 'controlsource' Why is this simple
opertion so difficult?


Because the Expression Service (which evaluates control
source and query expressions) does not include VBA variables
in its name space. The only VBA thingies that are available
throughout all of the components of Access are public
functions in standard modules. That provides one way to
achieve your goal. VBA variables are only available within
VBA procedures.

In the same module with the Public variable, create a
function with the only purpose is to return the value of the
variable.
Public MyVar As ...
Public Function GetMyVar()
GetMyVar = MyVar
End Function

Then you can set a text box's control source expression to:
=GetMyVar()

For reports, an alternative is to set a text box's value
using a line of code in the text box section's Format event
procedure:
Me.thetextbox = MyVay
 

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