Using query parameter in Access report - ms-access

I have a very basic access database where a query returns the sales
made within a set start date and a set end date.
The dates are set with two pop up boxes for the user to enter, first
the start date, and then the end date.
I have a report running off the back of this.
How can I (using VBA) get at these dates then display them on the
report - ie. the report says "Sales for Period:" and then shows the
"from date" and the "to date" that the user input.

You may find this tutorial helpful. It shows how to use a form to capture parameters for queries and reports and access the parameter values in VBA.

Related

MS Access Date Grouping is not working in report

I have created a simple Microsoft Access 2007 app of receiving and paying vouchers, everything is working properly but one thing that my mind doesn't solve.
I have created a report template of "Receiving Amount" where I want report be grouped in respect of receiving date. I have added a field named "Receiving Date" in "Group, Sort and Total" and when I generate it, it doesn't group the content in respect of date.
Adjust your Grouping and Sorting to use the expression:
Fix([Receiving Date])
I found the solution.
The reason of not grouping date wise because Access could not understand the date, like Gustav said, format is just for display but actual value is different and Sergey S said "If the field with date contains time. you won't be able to group the report".
Finally, I had to remove time from the date and keep it clear to Access so it can group my report.
=MonthName(DatePart("m",[receiving date])) & " " & Format$([receiving date],"d"", ""yyyy")
Where receiving date is the field name.

MS Access 2010 input date once for multiple sub reports

I've been banging my head against this for weeks, have Googled every permutation of the question that i can think of, and have still got nowhere, so any help would be really appreciated.
WHAT I NEED:
I need to generate a report, which pulls summaries of our referrals from the database. I have two reports which use the following queries as their Record Source:
SELECT referrals.origin_country, Count(*) AS ['number']
FROM referrals
WHERE (((referrals.referral_date) Between [Enter Start Date] And [Enter End Date:]))
GROUP BY referrals.origin_country;
And
SELECT referrals.first_language, Count(*) AS ['number']
FROM referrals
WHERE (((referrals.referral_date) Between [Enter Start Date:] And [Enter End Date:]))
GROUP BY referrals.first_language;
The queries are nearly identical, and the date range is the same for each one.
The issues is that when I generate a report which uses these two reports as subreports, I then have to enter the date range for the subreports twice (once for the Country of Origin Subreport, and once for the First Language Subreport.
My Access skills are not as advanced as I would like, and I'm wondering if anybody can tell me how to ensure that the user only has to enter the date range once?
I've tried
Using VBA to create a variable onLoad, but then couldn't work out how to use this variable in the Record Source Query...
Using VBA to create a function which sets a variable onLoad, but then couldn't work out how to use the function in my Record Source query...
Any suggestions would be greatly appreciated!
Create a form with fields for the start and end date, and a button on it, which launches your main form. Use the 'Embedded Macro' Wizard to open the chosen Report On Click.
Then, use [Forms]![FORM NAME]![FIELD NAME] in the query to access the date, for example:
SELECT referrals.origin_country, Count(*) AS ['number']
FROM referrals
WHERE (((referrals.referral_date) Between [Forms]![EAL Referral Search Form]![dat_termly_report_start] And [Forms]![EAL Referral Search Form]![dat_termly_report_end]))
GROUP BY referrals.origin_country;

Problems Creating Date Range with Date Picker for an Access Report

I have searched everywhere for this and tried different criteria but for whatever reason the form which has a control box set to open a report which is based upon a query will not pull the data within the date range. Instead keep getting enter parameter value dialogue box.
The criteria in the query is stated as Between [Forms]![Form1].[StartDt] And [Forms]![Form1].[EndDt]
The form has two date inputs StartDt and EndDt and is pointed to open the report. Without the above criteria in the query the form opens the report and produces all the dates. So at least it allows me to enter dates and is connected to the query and report but without the criteria fails to isolate data within the required range.
When I place into the query containing the criteria (as above) under the appointment date field all im getting are two parameter value dialogue boxes one after the other displaying Forms!Form1.StartDt and the second, Forms!Form1.EndDt.
Apologies for being long winded but am desperate to solve this issue am new to access.
Thanks to everyone for any input.
Iain
It seems you have an error in your names. One of the easiest ways to check form names is to use the immediate window. Type ctrl+G and you will end up in the code window with the cursor in the Immediate window. With the form open and a date filled in, type or paste
?forms!form1!StartDt
Into the immediate window and hit return. If you get an error, it means that you have a name wrong somewhere along the line, either your form is not called Form1, and form names can be a little complicated, or your control is not called StartDt. So this is where the version of Access comes in. In Access 2010, if you type Forms! on the criteria line of a query and wait a second, it will give you a list of forms. Pick your form from the list and type ! after the name, Access will come back with a list of controls. Pick your control. You should now have the right form and control name.

How to collect input via a form and pass to report query in Access

I have an Access 2003 MDB where I would like to present a small form for the user to input two parameters "Start Date" and "End Date". Thanks to another Stack Overflow user ("Kevin Ross"), I learned how to embed the form control directly in the query that is used by the report I would like to display.
SELECT q1.CasesAssigned, q2.WarningsIssued
FROM
(SELECT COUNT(*) AS CasesAssigned
FROM vwCaseDetail
WHERE DateAssigned Between [Forms]![frmReporting]![txtStartDate]
AND [Forms]![frmReporting]![txtEndDate]) as q1,
(SELECT COUNT(*) AS WarningsIssued
FROM vwWarningDetail
WHERE DateIssued Between [Forms]![frmReporting]![txtStartDate]
AND [Forms]![frmReporting]![txtEndDate]) as q2
I have tried two different ways to open the report and pass the users input:
After the user enters parameters I call DoCmd.OpenReport "myReport", acViewPreview. The problem here is that the reports opens and close so fast I never even see it. Ideally I would like to close the input collection form and then open the report.
Inside the Report_Open event I have code that opens the form that collect the users input. The input collection form opens, however I still get prompted by the report to enter in the two parameters. The report does not seem to be gathering the parameters from the input collection form.
Any suggestions on the proper way to pass data collected on a form to a report? Thank you.
Well,
The problem should be the logic of what your wantig. Why do you want a report calling a form? Why not a form in wich you fulfill the parameters then call the report?
You can perform your requisites in this way:
Create a form containing the fields corresponding to your desired parameters (Eg two textboxes called Param1 and Param2, in a form called Form1)
Create a query that retrieves the data for your report, referencing, in the conditions field, the parameters in the form (In the example, [Forms]![Form1]![Param1] and [Forms]![Form1]![Param2]). Also, right clik on a empty space of query builder and select "parameters". Inform all the parameters (with the entire strings [Forms]![Form1]![Param1] and [Forms]![Form1]![Param2]) with the correct data type. Let's call this query Query1
Create a report based on Query1. Lets call this report as Report1
Back to Form1, create a button (use the Wizard, its faster) for calling Report1.
Execute the Form1, in runtime fill the textboxes with the desired parameters then click the button. Make sure that you have data in your tables wich corresponds the Query.
In the other parts of your application, instead you call Report1 directly, call the Form1 that will manage Report1 querying and showing.

Access Report - Show Week Ending Date

I have an Access 2000 report based on a query like this
SELECT
...
FROM Clients AS wc INNER JOIN ...
WHERE ((wo.OfferStatusID)=3) AND
((DatePart("ww",[wo.StatusTimeStamp]))=DatePart("ww",[Enter Week End Date]))
AND ((Year([wo.StatusTimeStamp]))=Year(Date())));
The where clause allows you to enter the 'Week End Date' and it finds all of the records for the Sunday-Saturday week that contains the end date.
My problem is I need to include the Saturday end date on the report so that the header reads '... for week ending 5/9/09' and I can't figure out how to get that date without the query asking me for it a second time.
Is there a way to force Access to return the parameter entered as another field in the results, or another way to get that week ending date?
Continuing to poke around in the query designer I discovered that I could add this to the SELECT clause and get the value entered added to each row:
[Enter Week End Date] AS WeekEndDate
This works, but I am still open to other suggestions.
You could stack two queries (make one the source of the other). This would be pretty MS Access'y. However, if you have it working now, I'd stick with what you have. It's probably cleaner.
Another approach is to use a form to grab the query params first, and reference the form control in the query. For instance, with your example, create a form called frmGetDateParam, and add a textbox called txtDate. Change the format to a date, perhaps add some validation, doesn't matter. Add a command button to the form which opens up the report. Then, change your query to look like this :-
SELECT
...
FROM Clients AS wc INNER JOIN ...
WHERE ((wo.OfferStatusID)=3) AND
((DatePart("ww",[wo.StatusTimeStamp]))=DatePart("ww",Forms!frmGetDateParam!txtDate))
AND ((Year([Forms!frmGetDateParam!txtDate]))=Year(Date())));
You can also reference Forms!frmGetDateParam!txtDate as a field on your report.
The only downside to this approach is that if you try to open the query/report without the parameter form being open, then the query will still prompt you for the date value.