This happens with my alarm which is on the mains when we have a power failure. I then put the code into the house alarm, turn it on and then turn it off and that seems to work. Have no idea why though.
I have the same problem at the moment and it is driving me mad, why does it happen when its connected to the mains? will get a new battery and pray it stops.