@kath0722 the query is already defined above the if statement, perhaps you forgot to declare it, otherwise it should work.