Remove button permanently by macro

Hi,

I have come across a number of examples as how to toggle visibility/enable properties for buttons and other controls all of which work well - until the database is restarted.

So for example, I have a database with demo data, sort of like a tutorial. On the System Config form I have a button titled remove demo data, which runs a simple script clearing all the tables, resetting counters etc.

Once all of that is accomplished I would like to “permanently” hide or delete the button via code to prevent someone from clicking the button again thus destroying their own data. Can this be done?

Thanks

Hello,

The only way to “permanently” do something is to actually remove (delete) the control. This is not straightforward.

You can remove a control (shape) from the drawpage but it is only until you open the form again. To completely delete it you must open the form in edit mode. This can be done with:

ThisDatabaseDocument.FormDocuments.getbyname( "YOUR_FORM" ).openDesign

Next you need to find and delete the control. Code for that can be found in the answer by @JohnSUN in this post → Macros and deleting

Then Save & close the form. Can do with macros. Sample code in this post → is it possible to save and reopen a file from a macro

An alternative may be to remove the macro from the button event and then simply hide the button. Code to alter/remove macros from events can be found in the sample in my answer here → How to access the settings under the ‘Events’ tab of a form control to get / set the routines?. There is also a link to the originating code.

1 Like

Thank you, much appreciated!