Hi:
This sounds quite a bit like the functionality in the Qdabra Contact Selector. While that template part uses our AD Web Service to provide it with data, the logic is similar to what I think you are trying to do. Why not download it here, open it in design mode, and take a look at the rules?
If that doesn't help, perhaps you could post some more information on the command you are trying, and the error you are getting, or what exactly is happening when you are trying, for example, to insert?