Use Global Variables to Filter a report

crimmelcp

Registered User.
Local time
Today, 12:59
Joined
Sep 6, 2007
Messages
15
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
 

Attachments

  • viewreports.jpg
    viewreports.jpg
    53.1 KB · Views: 218
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 & "#"
 
all reports are based on queries

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"));
 

Users who are viewing this thread

Back
Top Bottom