The Mishna Berura says not to do Melacha 30 or 20 minutes before sundown. May one refrain from Melacha without formally accepting Shabbos in case something comes up, and when should one make the formal acceptance?

Indeed, even thou it is recommended to stop work about a half an hour before the Shekia (sunset) that marks the beginning os Shabbos, when in need one may reduce that time. However, one should even in need accept Shabbos at least five minutes before the Shekia, and stop all work to comply with a minimum of the necessary mitzva of Tosefes (addition) to Shabbos, at the beginning and end of the day.