0

I've made a macro to get information about the user to autofill two fields, name and last name. It works and display the information in the fields. In my form, they are both linked a field in the database. My issue is that when I save my form, the data written in those two fields doesn't stock in the database. Do I have to make something special in my macro to let the form know that the field isn't actually empty ?

This is the macro

Sub getMotherFirstName

Dim oFormDocs,oCallFormDoc,oForm,oComponent as object
Dim valueData As String

oForm =thisComponent.Parent.FormDocuments

rem ThisComponent.Drawpage.Forms.getByName("Form").getByName("Boxtest").Text = "hey you "
rem valueData = ThisComponent.Drawpage.Forms.getByName("HomeForm").getByName("Boxtest").getCurrentValue()
if oForm.HasByName("F_HOME") then 
    oForm = oForm.getByName("F_HOME")
    valueData = oForm.Component.DrawPage.Forms.getByName("HomeForm").getByName("prenom_box").getCurrentValue()
    ThisComponent.Drawpage.Forms.getByName("Form").getByName("prenomMere").Text = valueData
    getMotherLastName
End if
End Sub

1 Answer 1

0

Here is a copy of the answer you accepted at https://ask.libreoffice.org/en/question/316923/why-filled-field-with-macro-doesnt-stock-in-database/.

You have to .commit() the changed field(s) to the form. An updateRow() will store the current (changed) row to the database.

If your changes may result in other changes, perhaps filters or sub-form you may consider field.refresh() or/and to .reload() the form.

(It is described in the handbook for Base, but I have only the german version here, so I can only suggest to search the chapter on macros for the functions mentioned above in your language.)

Note: I've read through instructions such as https://meta.stackexchange.com/questions/4708/what-to-do-with-cross-site-duplicates but am still not really clear on how to handle such cross postings correctly. One thing is clear: A simple link will presumably break next month when the Ask site goes away, leaving the information inaccessible. So I copied the information instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.