@OP,
Just to make sure, this is intended to be a single user system that cannot allow two users to work on Parent records at the same time?
The " Where MainID is Null;" means if you have more than one person entering entries in tblLineUnitEntries at the same time, who ever trips this code FIRST...