Argument passing

  • Thread starter George Papadopoulos
  • Start date
G

George Papadopoulos

Hello everybody

How can I pass an argument from a form to a report? I can pass arguments
from a form to another form via the statement :

DoCmd.OpenForm stDocName, OpenArgs:=Me.[Kwdikos_episkeyhs]

Then I can access it from within the newly opened form. Can I do something
similar with reports?

George Papadopoulos
 
N

Nikos Yannacopoulos

George,

Provided you keep the form open while you run the report, you can reference
form controls directly from the report, e.g. you could set a report
control's controlsource to:
=Forms("FormName").Controls("ControlName")

If this doesn't work for you, you could use a public variable to hold the
parameter:
Public My Param As ... '(parameter type)
set its value from the form through a line at the beginning of the command
button code:
MyParam = Me.ControlName
and a simple function to return the parameter value:
Function Get_MyParam()
Get_MyParam = MyParam
End Function
Then the parameter value is available to the report (and any other db
object) by calling function Get_MyParam().

HTH,
Nikos
 
G

George Papadopoulos

thx, Nikos.

The general idea is sound. Now I have to shuffle through several technical
hurrdles to get it working. I`m trying to read the parameter from the Open
event of a report. Then, I want to change the recordsource via a query based
on the parameter I read.

Will that work?

Ï "Nikos Yannacopoulos said:
George,

Provided you keep the form open while you run the report, you can reference
form controls directly from the report, e.g. you could set a report
control's controlsource to:
=Forms("FormName").Controls("ControlName")

If this doesn't work for you, you could use a public variable to hold the
parameter:
Public My Param As ... '(parameter type)
set its value from the form through a line at the beginning of the command
button code:
MyParam = Me.ControlName
and a simple function to return the parameter value:
Function Get_MyParam()
Get_MyParam = MyParam
End Function
Then the parameter value is available to the report (and any other db
object) by calling function Get_MyParam().

HTH,
Nikos

George Papadopoulos said:
Hello everybody

How can I pass an argument from a form to a report? I can pass arguments
from a form to another form via the statement :

DoCmd.OpenForm stDocName, OpenArgs:=Me.[Kwdikos_episkeyhs]

Then I can access it from within the newly opened form. Can I do something
similar with reports?

George Papadopoulos
 
N

Nikos Yannacopoulos

George,

To the best of my knowledge, to change the report recordsource you need to
open the report in design view; not very convenient and, what's worse, not
feasible at all in an .mde, which denies access to the design.
Working alternative: use the code behind the command button which opens the
report to calculate your parameter before you actually open the report, then
use that to change the querydef programatically (the one that serves as the
report recordsource).
Unless, of course, what you're after is something simple, such as, for
instance, a filter (e.g. a date range or a Kwdikos_Episkeyhs etc.); in that
case, go to the design on your select query which serves as the recordsource
for the report, and in the criteria line make a reference to the control on
the form.

HTH,
Nikos

George Papadopoulos said:
thx, Nikos.

The general idea is sound. Now I have to shuffle through several technical
hurrdles to get it working. I`m trying to read the parameter from the Open
event of a report. Then, I want to change the recordsource via a query based
on the parameter I read.

Will that work?

Ï "Nikos Yannacopoulos said:
George,

Provided you keep the form open while you run the report, you can reference
form controls directly from the report, e.g. you could set a report
control's controlsource to:
=Forms("FormName").Controls("ControlName")

If this doesn't work for you, you could use a public variable to hold the
parameter:
Public My Param As ... '(parameter type)
set its value from the form through a line at the beginning of the command
button code:
MyParam = Me.ControlName
and a simple function to return the parameter value:
Function Get_MyParam()
Get_MyParam = MyParam
End Function
Then the parameter value is available to the report (and any other db
object) by calling function Get_MyParam().

HTH,
Nikos

George Papadopoulos said:
Hello everybody

How can I pass an argument from a form to a report? I can pass arguments
from a form to another form via the statement :

DoCmd.OpenForm stDocName, OpenArgs:=Me.[Kwdikos_episkeyhs]

Then I can access it from within the newly opened form. Can I do something
similar with reports?

George Papadopoulos
 

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