Thanks again Mark, it solved it but it was now changing $indexcount somewhere in <showform>, so before it was showing the listing of documents it changed the indexcount back again to its old value. Below is the code I've used to solve this problem by using a temporary variable and assigning this to indexcount.