I copied and pasted your code and it works fine for me! I would try redoing it from scratch and if that doesn't work, try the old creating a new blank db then importing everything, as it sounds as if you might have a corrupted db. The part about it working originally and then conking out sort of supports this. The code itself is sound, and reflects my own for the most part (instead of the standard error message if you're on the first record and try to go to the previous one, I have it "wrap" around to the last record).
Good luck!