Access VBA Requery not available now Error 2046

I am trying to refresh 2 queries, MyTaskQuery and MyTaskActions Both queries contain an INSERT SLQ statement to insert values from other tables in to table MyTasksTbl

The Query MyTaskQuery then selects the actions from MyTasksTbl that have my username.

When I've added the Delete SQL command (to remove any completed/closed actions and ensure there are no duplicates), I get a

Run-time error 2046, The command or action 'Requery' isn't available now.

Can anyone advise me why I am getting this error? The code runs on form_load()

SQL = "Delete * From MyTasks Where UserName = '" & User & "';"

DoCmd.Requery MyTaskQuery
DoCmd.OpenQuery MyTasksActions

1 answer

  • answered 2018-01-16 15:57 Erik von Asmuth

    You can only requery open objects. You can get this error when trying to requery a closed object.

    You can test if a query is opened before requerying with the following code:

    'Since you aren't using apostrophes, I assume the query name is stored in a variable
    If CurrentData.AllQueries(MyTaskQuery).IsLoaded Then
        DoCmd.Requery MyTaskQuery
    End If

    Note that opening an object just to requery it is pointless, since it already requeries when opened.