Hi nige1979 and Welcome to the board.

When you post code please place that code in code tags, here is a link that will help you with that, The Post/Reply Formatting Box and How to use it

I think the reason your getting that error is because this script is expecting to have a UDF in it called PriMapState, you can find it here. If you copy it into your script I think your error will go away.
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)