You will need to check to see if you are on the last record in the code and if so not have it move to the next one. For example:
If Me.CurrentRecord < Me.Recordset.RecordCount Then
DoCmd.GoToRecord , , acNext
Else
'[If the condition is not true, then we are on the last record, so don't...