>text TO m.cmd NOSHOW TEXTMERGE > SET XACT_ABORT ON; begin transaction > -- First Command >delete from crpr_sum where date=?Thisform.text3.Value and vou_no=?Thisform.text1.Value > -- Second Command declare @lastSNo INT; -- Use correct type of the vou_no in the table select @LastSNo = MAX(vou_no) from dbo.crpr_sum where date=?thisform.text3.Value" > SET @lastSNo = ISNULL(@lastSNo,0) + 1; -- Third Command > >INSERT INTO crpr_sum( >vou_no,date,vou_type,acc_code,acc_name,sales_r,vehicle_no,bilty_no,tpt, >driver,cr_amount,dr_amount) >values( >@lastSNO,?thisform.text3.value,'PR',?thisform.text10.value, >?thisform.text11.value,?thisform.text13.value,?thisform.text14.value, >?thisform.text15.value,?thisform.text16.value,?thisform.text2.value, >?thisform.text22.value,0) select @LastSNo as LastSNO commit transaction >ENDTEXT > > > if sqlexec(m.con, m.cmd, 'csrResult')<0 > aerror(laerror) > messagebox(laerror[1,2]) > > else thisform.text1.value = csrResult.lastSNo > endif > use in select('csrResult') > > >I made corrections inline in your code. I need to run right now, so I hope you will be able to get from there. The code is strange by itself, but I didn't try to analyze it in details. If you can explain in English its purpose (e.g. why you're deleting rows and then inserting, what are you trying to achieve), then we can provide better suggestions.