Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Have criteria in report header?

Posted on 2000-03-06
7
Medium Priority
?
220 Views
Last Modified: 2009-12-16
When we run a report it asks for two dates (start and finish), how can we have these show in the report header?
0
Comment
Question by:treyjeff
7 Comments
 
LVL 6

Accepted Solution

by:
blakeh1 earned 15 total points
ID: 2588943
Your best bet would be to declare the parameters in the query. Under the Query Menu choose, paramters, enter in the values. After this add a field for each parameter to the grid as new fields. then you can just add them directly from the field list in design view for the report.
0
 

Expert Comment

by:rpm97
ID: 2589198
Another way would be to create a form with two unbound text boxes, one for beginning date (beginningdate_txt) and one for endingdate (endingdate_txt).  Then in the criteria section of the your query for the date on which you are running your report, enter "between forms!yourform!beginningdate_txt and forms!yourform!endingdate_txt" (without the quotes).

When running the report, you can set yourform.visible = false, and add the fields into your report the same way as in the criteria in the query (forms!yourform!beginningdate_txt and forms!yourform!endingdate_txt)

0
 
LVL 7

Expert Comment

by:Believer
ID: 2589340
A third option...
I have grown *very* fond of putting report parameters into a local work table.  Then I tie the table into the query used by the report.  Voila!  No more Forms!Formname!FieldName...
Can also run reports *without* having the form open.
Here's a work table, tblOptions, for your specific situation (e.g. from/to date parameters):
bytWork is a byte field with:
  default value 0 (zero),
  validation rule"=0",
  Required=Yes,
  Indexed=Yes (No Duplicates)
datFrom is a date field
datTo is a date field

bytWork is only in the table to make sure that only one record ever gets put into the table.

Go into the query that your report is based on and add tblOptions to it.  Do not link this table to any other table in the query.  Add the fields [datFrom] and [datTo] to the query grid.  On the criteria row for the date field used by your report, type:
  Between [datFrom] And [datTo]

In your report, [datFrom] and [datTo] will now be available as normal fields that you can drop in the report header.

Side note: If your query happens to already have multiple tables and any of them are joined with arrows (Left outer join, etc.) then you will get an error when you run this.  To solve that problem, don't put tblOptions in the query.  Instead, define a NEW query which contains tblOptions and the original query.  Drag all the fields to the grid from your original query and tblOptions.  Add the "Between" criteria as described above.  To get these dates to show up in your report header, put them all by themselves in a subReport based solely on tblOptions.

Now for the user interface which runs the report... Bind the form to tblOptions and drop the fields on the form.  Add a buton to open the report.  In the code behind the button, *before* you run the report, DoCmd.RunCommand acCmdSaveRecord.  That will force access to save the dates to tblOptions before the report runs.

<Whew.>  I think I covered everything.  If not, I'm sure I'll hear about it! (lol)  This may sound like a bit of work, but it really ain't that bad.  It makes overall application design a lot easier!  You won's miss those "Forms!Formname!FieldName..." expressions a bit, I promise!!

0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 1

Author Comment

by:treyjeff
ID: 2589452
Well in our query we have it set under query to ask for start date and finish date :)  I just want the easiest way :)
0
 
LVL 7

Expert Comment

by:Believer
ID: 2589471
treyjeff,
I'm all for easy, too, but I'm also for nice-to-the-user.  (I'm not trying to be mean to you, I promise!)
Another cool side-effect is that the criteria the user enters are saved.  Next time the report prompt opens, they can see the values they used last time.
0
 
LVL 7

Expert Comment

by:Believer
ID: 2589496
A couple more general comments about using this method...

First off, this method is *not* well-suited to a front-end that is run by multiple users.  By that I mean if several people have shortcuts to the (front-end) database running on a network.  Each user's change to the report parameters can affect the other users.  If you install a separate font-end on each user's machine then you will have no problem.

Next, if you are doing a different kind of parameter this gets even easier.  Let's use "Customer" as an example...  If you have a table of customers (tblCustomers), add the customer field, lngCustomerID, to tblOptions and make it a combo box on the report prompt form (assuming that you have a customer lookup table, of course).  Now when you add tblOptions to the report's query, link [tblOptions].[lngCustomerID] to [tblCustomers].[cntCustomerID].  The query is now customer-specific... no query criteria!  Only records where [tblOptions].[lngCustomerID] match [tblCustomers].[cntCustomerID] will be included in the recordset.

That's all I can think of for now...
0
 
LVL 1

Author Comment

by:treyjeff
ID: 2597744
It worked :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

886 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