Help with VBA filter code

Edoardo Maino 1 Reputation point
2022-03-29T10:15:57.08+00:00

Hi all,
I have this code in an Access database that create a table, runs two queries and append them into the table.

I would like the final data to be filtered only to show the selected month.

but for some reason the DoCmd.ApplyFilter doesn't work.

this is the error I get:
"Run-time error '2046':
The command or action 'ApplyFilter' isn't available now.


Sub CreateReport()

'Create a new table (and delete the old table)
DoCmd.RunSQL "SELECT * INTO REPORT_TABLE FROM QRY_Report_A;"

'Adds in the the next table by appending
DoCmd.RunSQL "INSERT INTO REPORT_TABLE SELECT * FROM QRY_Report_B;"

'Apply filter for the selected Month
DoCmd.ApplyFilter , "MONTH = '2022_02'"

MsgBox "Code has completed, starting at " & t & " and ending at " & Time()

End Sub

0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tom van Stiphout 1,531 Reputation points MVP
    2022-03-31T04:45:47.423+00:00

    I would like the final data to be filtered only to show the selected month.

    What exactly do you mean? Filtered when opening a form with this data, or a report? or ...

    0 comments No comments