Does anyone know how to filter data in a query in code?
This is what I assumed would work but I am hitting some strange "Can't find the field" errors:
Queries![MyQuery].Filter = stMyFilter
I am creating an SQL string in stMyFilter based on selections the users make on the form. They then select which report they want to view and I code the reports to open like so:
DoCmd.OpenReport MyReport, acViewPreview, , stMyFilter
This works like a charm on most my reports, but the current report I am working on starts with a separate query. The fields which I wish to filter are only in the query, sorting and grouping in my report is too complex to add any more fields.
I would appreciate any comments or suggestions. Thanks!
This is what I assumed would work but I am hitting some strange "Can't find the field" errors:
Queries![MyQuery].Filter = stMyFilter
I am creating an SQL string in stMyFilter based on selections the users make on the form. They then select which report they want to view and I code the reports to open like so:
DoCmd.OpenReport MyReport, acViewPreview, , stMyFilter
This works like a charm on most my reports, but the current report I am working on starts with a separate query. The fields which I wish to filter are only in the query, sorting and grouping in my report is too complex to add any more fields.
I would appreciate any comments or suggestions. Thanks!
Last edited: