Well Les actually provides code for that here on the last post but the rest of the thread may be a good read for you as well.

Newbie Question (Write AD Object)
http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB13&Number=156871