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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display a global variable in textbox 1

Status
Not open for further replies.

lenichol

Programmer
Dec 9, 2002
2
US
In Access 2002, how do you access a public, globally-declared variable from a report? I have a textbox on my report that needs the contents of this variable, such as in the following sample code:

=gdtCutoffTime

When I finish the edit and move off the field, Access changes it to =[gdtCutoffTime] and then asks me for a value when I run the report. What is the correct syntax or method to use a variable on a report?
 
Hi,
I believe it is most appropriate to place this in the OnFormat event of the report section containing this textbox.
Example:
txtTimeCutoff.text = gdtCutoffTime HTH,
Randy Smith
California Teachers Association
 
I am replying to share a way that I have found that works. I have tried what Mr. Smith has suggested, and that works to display the value on the report. However, I have not been able to use that value elsewhere on the report. My line of code in the textbox in the Control Source field is the following:

=IIf(Time()<gdtCutoffTime,Now(),DateAdd(&quot;d&quot;,1,Now()))

When I leave the textbox, Access places [] around gdtCutoffTime and asks for a value when I run the report just like a parameter query.

Solution: In a standard module, create the following procedure:

Public Function RptVar() as Date
RptVar=gdtCutoffTime
End Function

My textbox Control Source will now read

=IIf(Time()<RptVar(),Now(),DateAdd(&quot;d&quot;,1,Now()))

This solution works for me. If anyone knows a better or more elegant way, please reply.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top