yeah, I got a hand with it this morning, (thanks una!). Instead of using $id, I use this:$test = get_record("course_modules","id",$id);
and then insert $test->instance instead of $id wherever needed.
all working fine now!!
thanks for your help,
Jonathan