Enabling control in AfterRecordChange no longer works in LO 24.8.3.2 Base form

Windows 11 24H2 (No windows-11 to select when adding a new topic)
64-Bit LO.

I use following code:

function Form_AfterRecordChange(Event as object)
Dim oForm as object
dim oControl as object
dim oController as object
dim oControlView as object

oForm = ThisComponent.DrawPage.Forms.getByIndex(0)
oController = ThisComponent.CurrentController

if oForm.GetPropertyValue("IsNew") = True then
	OControl = oForm.GetByName("Date")		' bound Date control
else
	OControl = oForm.GetByName("buNew")      ' button
endif
oControl.Enabled = True
oControlView = oController.GetControl(oControl)
oControlView.SetFocus

I have used MRI to confirm that the control IS Enabled.
This worked in LO 7.6.4.1.

Might be it need a refresh (or reload) of the form.

Might be this helps:

SUB FormReloadControlsRefresh
	DIM oDocument AS OBJECT, oDispatcher AS OBJECT
	DIM Array()
	oDocument = ThisComponent.CurrentController.Frame
	oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
	oDispatcher.executeDispatch(oDocument, ".uno:Refresh", "", 0, Array())
END SUB

Hi RobertG, Thanks for the suggestion but using your FormReloadControlsRefresh or doing an oForm.reload from AfterRecordChange causes an infinite loop that eventually does very bad things to my pc.

ask114862.odt (13.7 KB)

EDIT: Form macros are complex. Since the above simple sample constantly changes the form control models, the embedding document model becomes modifed too. You can reset the modified status of the document or you can modify the form control itself rather than its model. Like this: ask114862_2.odt (12.1 KB)

Hi Villeroy,
Thanks very much for your examples.
The method in ask114862_2.odt (using Control View Model) works fine in LO 24.8.3.2 for text boxes and date controls but does not work for buttons. For buttons I had to continue to use the Control Data Model:
ie
oForm.GetByName(“buNew”).Enabled = True

I’ve been studying AndrewBase.odt section 4 Forms, The internal object model.
I hope “Control Data Model” means something to you. You seem to use different names than AndrewBase.odt.
I slightly altered your method in ask114862_2.odt as follows (for enabling textbox’s, date controls & comboboxes):

Dim oForm as object : oForm = ThisComponent.DrawPage.Forms.getByIndex(0)
Dim oControl as object
Dim oController as object : oController = ThisComponent.CurrentController
oController.GetControl( oForm.GetByName(“Date”)).SetEnable(True)

AndrewBase.odt says in section 4.1.3 “A control’s data model is in a form”:
Use the control’s (data assumed?) model to enable or disable the control.

That no longer works in LO 24.8.3.2 for text boxes, date controls or comboboxes.

I don’t understand why you said “You can reset the modified status of the document”?
Were you referring to the form IsModified property? How would that help enabling or disabling controls?

ask114862_3.odt (12.2 KB)

EDIT: There seems to be something buggy (and it’s not my macro).
Back to the simple approach of my first sample:
ask114862_4.odt (13.3 KB), but this time we set File>Properties>Security>“Open read-only” (embedded forms are read-only anyway)

I don’t understand. I see your ask114862_4.odt works (for text boxes and the button) by setting the “control data model”.Enabled property.
However, when I open the ask114862_4.odt and look at File>Properties>Security>“Open read-only”, it is NOT checked, so how do I get my forms in my .odb to work?

Just save my file with that option being checked, and it won’t change by mere navigation. When working with an embedded form, this is not a problem. Possibly, I uploaded the file too early. I was in a hurry.
P.S. Mind that you save the file (or embedded form respectively) with the current enabled states.

Now I’m more confused. To enable/disable a bound Date Control in one of my forms I must use

[Control Data Model].Enabled = True|False

and in another form I must use

[Control View Model].SetEnable(True|False)

I can find no reason for this. At least I know one of these methods works.

Do yourself a favour and avoid macro programming. Nobody understands all that rubbish. It is a constant process of working around.
Apart from this general advice, your problem is not reproducible:
ask114862.odb (21.3 KB) Various form controls enabled/disabled on left/right side.