[SOLVED] Closing a form error: DataSet is not in edit or insert state ... lazarus / 16-Databases ---------------------------------------------------------------------- 1HuntnMan · 2024-10-23 16:47 I've run into this once in awhile but deciding that I am not checking properly when a form in this database app is closed. If I open and edit or insert not an issue but if in testing I open a form and just move to the next record and then click the Close button, I'm checking whether the user might have edited a record to make sure to post before closing for example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TFrmSalesOrdersMgt.SpdBtnCloseSOClick(Sender: TObject);begin  try    if DbfSO.Modified then      DbfSO.Post;  finally    DbfSO.Close;  end;  DbfProposal.Close;  DbfContacts.Close;  DbfPhotogrphr.Close;  DbfFirmType.Close;  DbfJobType.Close;  DbfStatus.Close;  FrmSalesOrdersMgt.Close;  FrmSalesOrdersMgt.Free;end; Is there a better way to check other than if DbfSO.Modified ? See attached error. Tks anyone ---------------------------------------------------------------------- Handoko · 2024-10-23 17:01 I am not sure but maybe: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if DbfSO.Active then    if(DbfSO = dsEdit) or (DbfSO = dsInsert) then    try        DbfSO.Post;      finally        DbfSO.Close;      end; If you get a compile time error, you need to put DB in the uses clause. ---------------------------------------------------------------------- 1HuntnMan · 2024-10-24 16:04 Tks Handoko, made it work ... Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   if DbfSO.Active then    if (DSSO.DataSet.State = dsEdit) or (DSSO.DataSet.State = dsInsert) then      try        DbfSO.Post;      finally        DbfSO.Close;      end;