[Base] Deleting row in Form from BASIC – “Result set is read only” Error

2 tables in one-to-many relationship, tblOrders and tblOrdersDetails. Relationship option for Deletion is Delete cascade.

2 forms for each table with Table Controls, created with wizard

Option Explicit

Dim oDialog As Object

Sub OfferDelete(Event As Object)

Dim oForm As Object
Dim oLib As Object
Dim oLibDlg As Object

	DialogLibraries.loadLibrary("Standard")
	oLib = DialogLibraries.getByName("Standard")
	oLibDlg = oLib.getByName("dlgCheckDelete")
	oDialog = CreateUnoDialog(oLibDlg)
	oForm = Event.Source.Model.Parent

' this is a Dialog for double-checking the deleting action
    If oDialog.Execute() = com.sun.star.ui.dialogs.ExecutableDialogResults.OK Then
		oForm.deleteRow
    	oForm.reload
    End If

End Sub

MainForm has the Data properties:

  • Allow additions – No
  • Allow modifications – No
  • Allow deletions – No

oForm.deleteRow give me the “Result set is read only” Error

If I set in GUI

  • Allow deletions – Yes

everything is OK

But if I add oForm.AllowDeletes = True while in GUI is

  • Allow deletions – No

again, same error.

oForm.AllowDeletes = True
oForm.deleteRow
oForm.reload

Although, if I only run step-by-step until this inclusive

oForm.AllowDeletes = True

and checking in GUI, the setting becomes

  • Allow deletions – Yes

So, why manual setting in GUI is OK, but programmatically (with same result in GUI) is not OK? And how I could solve it? The solution “use the GUI” is a no-solution, It’s mandatory for final user to double-check with the Dialog

Clipboard01

Adding the offers with SQL works OK, I assume that the updating and deleting does, but I would like the deletion to be a simple, reusable procedure, because I need it in many places and it is basically dependent only on the Form and cursor position.

I tried Wait 1000 or Wait 2000

oForm.AllowDeletes = True
Wait 1000
oForm.deleteRow

but no success.

Version: 24.2.2.2 (X86_64) / LibreOffice Community
Build ID: d56cc158d8a96260b836f100ef4b4ef25d6f1a01

Processor Intel(R) Core™ i3-9100 CPU @ 3.60GHz 3.60 GHz
Installed RAM 16,0 GB (15,8 GB usable)
System type 64-bit operating system, x64-based processor

Edition Windows 11 Pro
Version 22H2
OS build 22621.3527
Experience Windows Feature Experience Pack 1000.22700.1003.0

Welcome to the forum!
Could you upload a test file (middle button on the toolbar for preparing messages) containing data and macros?

No matter, how you set up the form, you can’t insert/update/delete from read-only result sets. If you can’t delete manually, your macro can’t neither.

Test delete row.odb (47.1 KB)

I think, you’ve got to reload the form after changing its access mode.

OK, I was expecting this, to not be able to modify something read-only. But in Base Guide 7.3 (Chapter 9 Macros pag. 405) say:

There is a simple command to delete a record; proceed as follows:

  1. Choose the desired record and make it current, as for a modification.
  2. Use the following command to delete it:
    oForm.deleteRow()

And I can to delete manually, but I don’t want the user to do that.

To control the deletion of records, use the Confirm Deletion form event.

Like here Apache OpenOffice Community Forum - [Solved] How to over-ride Confirm deletion event in macro? - (View topic) ?

Yes (minimum length of response on the forum is 10 characters :smile: ).