Question about passing form control value to report (1 Viewer)

dkmoreland

Registered User.
Local time
Yesterday, 21:37
Joined
Dec 6, 2017
Messages
129
To run this report I have, a form will open on which the user will select a start date and an end date, then enter a number that will be used in a calculation on the report. The control is unbound and the value is not stored in any table - it is used for calculation only and is determined by the user.

I know that I can use this as the control's data source

Code:
=[Forms]![Select KPI Date Range]![TxtNumKPINCR]

However, this only works as long as the form is open. How can I pass this to the report if the form is closed? I don't want to leave it open on the screen. I don't think a Where statement will work since there is no table or query behind this control.



Suggestions, please?

Thanks in advance.
 

isladogs

MVP / VIP
Local time
Today, 05:37
Joined
Jan 14, 2017
Messages
18,221
Save the value using a variable (or a tempvar if you use them)
Reference the variable in the report
 

dkmoreland

Registered User.
Local time
Yesterday, 21:37
Joined
Dec 6, 2017
Messages
129
Save the value using a variable (or a tempvar if you use them)
Reference the variable in the report

Can you give me an example of the DoCmd syntax for referencing that variable?
 

1268

Registered User.
Local time
Yesterday, 23:37
Joined
Oct 11, 2012
Messages
44
To run this report I have, a form will open on which the user will select a start date and an end date, then enter a number that will be used in a calculation on the report. The control is unbound and the value is not stored in any table - it is used for calculation only and is determined by the user.

I know that I can use this as the control's data source

Code:
=[Forms]![Select KPI Date Range]![TxtNumKPINCR]

However, this only works as long as the form is open. How can I pass this to the report if the form is closed? I don't want to leave it open on the screen. I don't think a Where statement will work since there is no table or query behind this control.



Suggestions, please?

Thanks in advance.
SQL make table. I am not sure if the variable riders discuss will persist. Never tried.

Sent from my SM-G950U using Tapatalk
 

dkmoreland

Registered User.
Local time
Yesterday, 21:37
Joined
Dec 6, 2017
Messages
129
SQL make table. I am not sure if the variable riders discuss will persist. Never tried.

Sent from my SM-G950U using Tapatalk

Why use make table? I don't really need to save this value past the point of generating the report.
 

1268

Registered User.
Local time
Yesterday, 23:37
Joined
Oct 11, 2012
Messages
44
Why use make table? I don't really need to save this value past the point of generating the report.
Because it cant be lost and it is ez to do.

Sent from my SM-G950U using Tapatalk
 

isladogs

MVP / VIP
Local time
Today, 05:37
Joined
Jan 14, 2017
Messages
18,221
Repeatedly making tables will bloat your database and is totally unnecessary for this purpose

There are at least 3 ways of transferring the value from form to report
The attached example database demonstrates each of these
1. Get the value of sngValue in the Report load event
2. Add the value as a field in the report record source
3. Set the value using OpenArgs

For simplicity I've used a public or global variable sngValue.
I could have used a tempvar but I tend not to do so

None of the methods use DoCmd code

In each case, the form is closed before the report loads
All work equally well - choose whichever you prefer

HTH
 

Attachments

  • ReportVariableTestDB.accdb
    572 KB · Views: 81
Last edited:

dkmoreland

Registered User.
Local time
Yesterday, 21:37
Joined
Dec 6, 2017
Messages
129
Repeatedly making tables will bloat your database and is totally unnecessary for this purpose

There are at least 3 ways of transferring the value from form to report
The attached example database demonstrates each of these

For simplicity I've used a public or global variable sngValue.
I could have used a tempvar but I tend not to do so

1. Get the value of sngValue in the Report load event
2. Add the value as a field in the report record source
3. Set the value using OpenArgs

In each case, the form is closed before the report loads
All work equally well - choose whichever you prefer

HTH

I'll give those a try. Thank you!
 

Users who are viewing this thread

Top Bottom