Connecting Tech Pros Worldwide Forums | Help | Site Map

Report from Query

Newbie
 
Join Date: Oct 2007
Posts: 29
#1: Dec 30 '08
I am not seeing how to accomplish this:
I created a from that uses a subform, the main form has two fields, category and date.
After I select a category and date, the appropriate records show in the sub form
I would like to know how I can send this data to a report that I created using the subform data.
Right now when I produce the report it displays all the records, I would like to filter the report using the my form/subform data.
Thanks
JAS

DonRayner's Avatar
Expert
 
Join Date: Sep 2008
Location: Canada
Posts: 494
#2: Dec 31 '08

re: Report from Query


In the record source for your report, Add criteria for your for your catagory and date. Base the criteria on your form. The code for the criteria would be something like below or you could just use the expression builder.

Expand|Select|Wrap|Line Numbers
  1. [forms]![YourFormName]![YourFieldName]
  2.  
Replace YourFormName with the name of your form. Replace YourFieldName with the name of the field that you are basing the criteria on.
Newbie
 
Join Date: Oct 2007
Posts: 29
#3: Dec 31 '08

re: Report from Query


I tried this but I keep getting [forms]![ScheduleLookup]![date] does not exist
(where Schedulelookup is my form and date is the field on the form

Is there maybe just a way to filter? where I can filter the report based on the two fields on my main form to return the data in the subform?

Thanks
Newbie
 
Join Date: Oct 2007
Posts: 29
#4: Dec 31 '08

re: Report from Query


I even tried this
strFilter = "[date]=" & Me![date] & " and [category] ='" & Me![category] & "'"
stDocName = "Schedule"
DoCmd.OpenReport stDocName, acPreview, , strFilter

But when I run the report I still get every record.
The immediate's window show the correct date and category
DonRayner's Avatar
Expert
 
Join Date: Sep 2008
Location: Canada
Posts: 494
#5: Dec 31 '08

re: Report from Query


Is your form open?

Using "Date" as a field name is probally what's causing the problem. Date is a reserved word in access that represents the current date. You should change the field name on your form to something else like ScheduleLookupDate or whatever.
Newbie
 
Join Date: Oct 2007
Posts: 29
#6: Dec 31 '08

re: Report from Query


strFilter = "[date]=#" & Me![date] & "# and [category] ='" & Me![category] & "'"
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#7: Jan 7 '09

re: Report from Query


The format for the OpenReport method is :
Expand|Select|Wrap|Line Numbers
  1. DoCmd.OpenReport(ReportName, _
  2.                  View, _
  3.                  FilterName, _
  4.                  WhereCondition, _
  5.                  WindowMode, _
  6.                  OpenArgs)
Naturally you would expect the FilterName parameter to be what you need. It isn't!!

Set up a WhereCondition string which is like a SQL WHERE clause but without the "WHERE" keyword.

PS. It's not a good idea to get into the habit of updating the design of an object (report) simply to apply filtering.
Reply