First, let's see what's actually happening. Add these lines to your code, and debug the script. What is the value of X ? Does it have any spaces in it ?
X = Trim(Cstr(Intkey)
Secondly, you said that OrderNum was computed. What is it's computational formula ?