View Full Version : Use Global Variables to Filter a report


crimmelcp
10-16-2007, 12:40 PM
To all:
I have several reports that use dates to filter the data.
Right now i am using datepicker to select a date and then store on a form variable.
Then in the report data query I use >= [forms]![viewreports]![begindate]

This works, but what I would like to be able to do is the following.

use date picker to select a date
store the selected date into a global report variable.(vrpt_begindate)
Then in the report data query I use >= [vrpt_begindate]

I have tried the on load in the report, but I cannot get it to see the variables.

Thanks
Charlie Crimmel

boblarson
10-16-2007, 12:59 PM
Instead of going through all of that hassle, why not just use the filter in the OpenReport code:

DoCmd.OpenReport "YourReportNameHere", acViewPreview,,"[KeyIDFieldOnReport]>= #" & Me.begindate & "#"

crimmelcp
10-16-2007, 04:35 PM
Bob:
All of my reports are based on queries.
Below is the SQL view of the query
Can I just change part of the where clause to reflect your code.
If I could get away from using [Forms]! then it would be easier to base the where clause on variables.

Thanks
Charlie Crimmel

SELECT HistoryTransaction.shift, HistoryTransaction.startdate, HistoryTransaction.company, HistoryTransaction.badge, HistoryTransaction.gateIn, HistoryTransaction.gateOut, HistoryTransaction.startdate, HistoryTransaction.starttime, HistoryTransaction.enddate, HistoryTransaction.endtime, HistoryTransaction.EmpNum, HistoryTransaction.Craft, HistoryTransaction.LastName, HistoryTransaction.FirstName, HistoryTransaction.class, HistoryTransaction.crdesc, HistoryTransaction.ssn, HistoryTransaction.companyname, employee.crew, employee.group, HistoryTransaction.totalminutes, HistoryTransaction.totalhours, HistoryTransaction.mins, HistoryTransaction.shours, HistoryTransaction.sminutes, HistoryTransaction.ehours, HistoryTransaction.eminutes
FROM HistoryTransaction INNER JOIN employee ON HistoryTransaction.badge = employee.CUSTPIN
WHERE (((HistoryTransaction.shift)=[Forms]![frmMainMenu]![Shift]) AND ((HistoryTransaction.startdate)>=(Format([Forms]![frmMainMenu]![BeginDate],"Short Date"))) AND ((HistoryTransaction.enddate)<=(Format([Forms]![frmMainMenu]![EndDate],"Short Date"))) AND ((HistoryTransaction.Craft)<"100") AND ((employee.group)="F"));