Well, the error means that a line has been created and saved and you are trying to change the item number. Is your program adding a line with a blank part number?? It seems to be treating the "blank line" as a saved line.
BTW, just say yes and the system will allow you to change the blank line to a real part number. However, your code's blank line could create other issues when posting ( it is not marked as non-inventory buy it cannot find a matching part number in stock ...)