Can you post your script with the edit you made?
You might also look for script trigger controlled scripts that may kick in and put the user back in preview mode after your script finishes executing.
Here's the script. It's pretty straighforward I would think.
It's attached to the OnLayoutEnter event for my Main Data Entry Form.
What mode are you in when you change layouts?
Have you enabled this trigger for that mode?
Otherwise this script might not actually be tripped by the change in layouts.