Sorry, I suppose I could have been clearer.
Have a look at this, which I hope will explain where the name formula code needs to go.
For the action button, you only need the first block of code I wrote (and you can delete all the example code that is present when an action button is created).