Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing criteria into a report from a form

Posted on 2013-11-27
4
Medium Priority
?
478 Views
Last Modified: 2013-11-27
I have a query (qry_report1) and a report (rpt_report1) that requires 2 inputs from the user - StartDate and EndDate. I have set up a form (frm_report) with 2 txt fields with datepickers where the user can set the dates. I have made a command button calling the report using DoCmd.OpenReport.

When I open frm_report and set the dates and press the button the setup works, but when I embed the frm_report in a navigationalform (frm_menu) and run it from here it doesn't work anymore. Instead I keep getting the enter parameter value dialogue box.

Whats the problem?
0
Comment
Question by:LarsDyrby
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 48

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 39680996
The problem is that the query for your report probably is directly referencing the controls frm_Report.  But Access no longer sees that form when it is embedded as a subform inside another form.

One way to do this would be to replace the references to the form with references to a global variable or tempvar; for more on TempVars, check out this Access Blog article.

What you would do is use the AfterUpdate event of those two date textboxes to populate your TempVar using code similar to:

TempVars.Add "StartDate", cdate(me.txt_StartDate.value)
Tempvars.Add "EndDate", cdate(me.txt_EndDate.Value)

Then in your query you would use:

SELECT * FROM yourTable
WHERE [DateField] >= [tempvars]![StartDate]
AND [DateField] <= [tempvars]![EndDate]
0
 
LVL 28

Expert Comment

by:omgang
ID: 39681003
How/where do you specify the values for the form fields?  In the query or the report itself, e.g. [Forms]![frm-report]![txtField1] ?  If so, then once you embed the form in another for the reference will no longer work.  You'll need to refer to the parent form and then drill down.

OM Gang
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39681016
the criteria in your query "qry_report1" is still looking for the form "frm_report" which now became a sub form when you placed it in "frm_Menu"..


1. remove the date criteria from your query

2. open the report like this

docmd.openreport "rpt_report1",,, "[datefrom]>=#" & me.textdate1 & "# and [dateTo]<=#" & me.textdate2 & "#"

that is the format you  should use...



post the criteria from query  "qry_report1", so we can correct the code above



.
0
 
LVL 28

Expert Comment

by:omgang
ID: 39681033
If you want to refer to the original form, which is now a subform of another form, you can refer to it in this way
Forms!frm_menu.form!frm_report!txtField1

OM Gang
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question