Please use code tags
I noticed that previousrec variable is not initialized. Opposing to class variables, the ones in procedures are not 0 when they are first defined.
Then also using sizeof as variable name may cause issues (later?) cause there is a system function named like that.
Bookmarks