I was not looking to create a full blown demo. I just thought it important to those looking at this post to find something that works. I already stated in my original comment that I personally believe it is preferable to learn and use the API
. You could take it and modify it how you want but it needs some work - just do not post something that is just slapped together as in you original post. I do NOT want this as it is to be a tutorial - for that it needs considerable work including error handling! Currently it is only some sample code executed by buttons on a form.
That is for the user to decide. It is easy enough to extract and do so. For posting here it is best to embed in the document to avoid multiple items and more instructions.
Again, did this to offer multiple options within the code. You can change as there are other methods as shown in the code.