Base - Macro changes form field but will NOT change table

I have a very simple form with the usual fields for the name, including one for a Preferred Name (or nickname). After entering the First Name (so “When losing focus” event) if there is nothing in the Preferred name control, the following Macro will put the First Name in as the Preferred Name:

Sub CheckFirstName

oController = thisDatabaseDocument.currentController
If not oController.isConnected then oController.connect

Dim sPrefName as String

oDoc = thisDatabaseDocument
oForm = ThisComponent.Drawpage.Forms.getByName(“MainForm”)
sPrefName = oForm.getByName(“txtPrefName”).Text
If sPrefName = “” Then
sPrefName = oForm.getByName(“txtFirstName”).Text
End If
oForm.getByName(“txtPrefName”).Text = sPrefName
oForm.isModified = true

End Sub

Without the line “oForm.isModified = true” the save icon does not activate. With it, the save icon activates BUT clicking it gets the error message that nothing has changed so it won’t save.

You use the property “text”. It is showing the text-content on the screen like a shape or something else.

oForm.getByName("txtPrefName").BoundField.UpdateString(sPrefName)

This will change the content in the datasource of the field. You won’t need to set the form modified after this action.

1 Like

Thanks, Robert. Have checked the “Solution” box on the original and given a like.