Button Script to delete Sales order with cancel code

Hello all,

I wrote a script with the goal to delete sales orders with a specific condition. So I can delete sales orders just fine its just that when the orders are deleted the cancel reason code is not flowing to history it is staying blank. I am even providing the value in the script. This is a button script that sits on Tab 1 of SO entry. I have tried a variation of code to force the UI (sCancelReasonCode = "" : oUIObj.InvokeLookup "SO_CancelReason", sCancelReasonCode) to bring up the cancel reason window and then it does go to history with a a code but the order status is left as "A". I would really like to just press the button it finds the orders I want to delete and it just goes to history with the cancel code I have chosen in the code. Code below. Any help would be appreciated.