PDA

View Full Version : SQL statement as Report record source



DBinPhilly
03-05-2017, 09:22 AM
I do very little VBA programming now, but did a lot long ago.
I have an Access form used to display the results of a generic lookup of a database. I build a SQL statement based upon fields in the form header and make it the record source of the form, with the result found records displayed in the body of the form.

I need to print a report using the same lookup criteria. How do I make the created SQL statement the record source of the report?

jonh
03-06-2017, 08:33 AM
Filters for forms, reports, dlookups, etc are just SQL WHERE criteria.

me.recordsource = "select * from table1 WHERE fld1 like '*foo*'"

Me.Filter = "fld2 like '*bar*'"
FilterOn = True
...
DoCmd.OpenReport "report1", acViewPreview, , Me.Filter