Does this code work?

If it does we can use it as a starting point and adapt it for your use.