0
votes

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.RunSQL SQL

DoCmd.Requery MyTaskQuery
DoCmd.OpenQuery MyTasksActions
1
Is that query always open when the form loads? You can only requery open objects.Erik A
Looks like that was exactly the problem. If you want to add the answer I will +1. Thanks.Tom36

1 Answers

3
votes

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.