That sorted the problem, I used: set page_num [ns_queryget page_num] to get the page number and then exported it as you said.
You've saved me a lot more time messing around with bits of code.
Matthew