Passing Variable String from Form to a Report Textbox

J

Jonathan Mulder

Hi,
I've developed a form that creates a series
of "WHERE ...." clauses (based on user input) that limits
the scope of records to be printed. I'd like to print
the string variable (i.e. "WHERE ....") in the report
header so that the enduser know what the limiting
criteria of the report was.
In my form, I have a variable called "strWHERE". How
can I pass the value of strWHERE to a text box in my
report header?
I've declared strWHERE as public in my module, but I'm
not really sure if that is needed...

Thanks for any help!

Jonathan H. Mulder
California Department of Water Resources
Red Bluff, CA
 
M

MGFoster

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You'll have to create a function in the report's code module that
returns the string from a function in the criteria form. Then set the

ControlSource of the TextBox in the report's header that retrieves the

value of the function in the report. The criteria form must remain
open
when the report runs. When the report closes, the criteria form can
be
closed. E.g.:

' Report's function to get criteria string:
Function GetCriteria() As String

GetCriteria = Forms!frmCriteria.GetCriteria()

End Function

Control Source of the TextBox that will display the criteria
on the report:

ControlSource: =GetCriteria()

====

' Declaration section of the criteria form
Dim m_strWhere As string

' Criteria form's function
Public Function GetCriteria() As String

GetCriteria = m_strWhere

End Function

' ... you procedure to add to the criteria string ...
.... etc. ...

====

Change the form name, as required.

HTH,

MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQDqGRIechKqOuFEgEQIgeACfccG4PlEW5ngHBqa0X5qTEdTIaYAAnib+
0Qyo8N0eqfsBb0pVWFtg5t1c
=CgAn
-----END PGP SIGNATURE-----
 
D

Doug in POrtland ME

There are likely many ways to do this, however this is one
I have used:

Create a hidden (txtBox.visible = False) text box on your
form, then save your WHERE clause to that text box. You
can then reference the text box in queries and reports
using the following syntax: Forms!frmXXX!txtXXX. For your
report text box, the control source = "=Forms!frmXXX!
txtXXX".

Alternately, when you open your report you can specify
strWHERE as the FilterName parameter in the
docmd.openreport method, then display the report's filter
property in the report text box (control source = "=
[Filter]".

Cheers,
Doug
 
M

Marshall Barton

Jonathan said:
Hi,
I've developed a form that creates a series
of "WHERE ...." clauses (based on user input) that limits
the scope of records to be printed. I'd like to print
the string variable (i.e. "WHERE ....") in the report
header so that the enduser know what the limiting
criteria of the report was.
In my form, I have a variable called "strWHERE". How
can I pass the value of strWHERE to a text box in my
report header?
I've declared strWHERE as public in my module, but I'm
not really sure if that is needed...

As long as the form is open and the variable is declared
Public in the form module's declarations section (before any
procedures), you can refer to it as a property of the form's
class module:
Forms!theform.strWHERE
 

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