openoffice-basicopenoffice-base

Reset button in Openoffice base


i want to add a reset button in my form. So txtstadiumName has to be empty after clicking on the button. It sounds simple but im struggling to find this. I know i have to use openoffice basic for this and use a macro.

This is what i tried:

TxtstadiumName=""

But nothing happens after clicking on the button. I related the event with the macro, so im confused, what am i doing wrong?

I used to work with vba in access and thats how it was done.


Solution

  • You're probably assigning the text field - which is an object with many different properties - to the variable TxtstadiumName by one of two methods. Either

    Sub YourMacro(oEvent As Object)
        oSubForm = oEvent.source.model.parent
        TxtstadiumName = oSubForm.getByName("TxtstadiumName")
    

    Or

    Sub YourMacro
        oSubForm = ThisComponent.drawpage.forms.MainForm  
        REM Make sure to change 'MainForm' to be your actual subform name
        TxtstadiumName = oSubForm.getByName("TxtstadiumName")
    

    Note that while Basic variables don't care about upper or lower case, the API method .getByName is case sensitive! The question has txtstadiumName in one place and TxtstadiumName in another, and it's important that whichever one is correct is the one in quotes inside the .getByName method.

    Once you have the text field object assigned to a variable, now you want to change one of its properties. In this particular case I believe the property name is text. So like this:

    TxtstadiumName.text = ""