How to assign a macro to an event by a macro

Win10 LO6.4.7.2 HSQL2.51

Hi all,

I would like a user to choose whether to be prompted for a login prompt or not. One can do this manually via the setup script which comes with the database split wizard(s)

by simply uncommenting line 76

Thinking of a checkbox in an options form to toggle the login requirement and guess the easiest way would be to swap between 2 setup scripts.
Now I found this brief code sometime somewhere and it seems to fit the purpose, however I think the last 2 lines prior to the end sub need to be adjusted to base

sub ForceMacro
dim Prop(1) as new com.sun.star.beans.PropertyValue
Prop(0).name = "EventType"
Prop(0).value = "Script"
Prop(1).name = "Script"
Prop(1).value = "vnd.sun.star.script:Standard.Module1.test?language=Basic&location=document" 
thiscomponent.sheets.getByName("Sheet2").Events.replaceByName("OnDoubleClick", Prop())
end sub

The original setup macro is attached to the Customize, On Open Doc event
The database window however does not seem to have a name but can be manipulated via

Const acDatabaseWindow = 102

Anyone come across a similar example ? Any pointers to what needs to be changed above will be greatly appreciated.

Thanks

1 Like

Hello,

Do not under the reasoning (or even some logic - options form?) of why you are attempting this. Seems like a security issue lurking.

Edit:
Regardless, your sample is not comparable to the request. It is a Event for a sheet and in comparison to modifying a form or control event, it is quite different.

You can access the Base and Form events with your code. Should be able to access with

ThisDatabaseDocument.Events.replaceByName("CHOSEN_EVENT", Prop())

End Edit

For Form controls (also for Base itself) see this post: How to programmatically get/set a form control’s events

To go another step, see the answer in this post: Register macro to Image Button. It also contains another link to more info with included sample and cross reference list of events in controls (on Calc sheet).

@Ratslinger Thank you, just playing with ideas, the secrity issue aside I think using a macro to assign macros to events would be away to ensure macros are not removed from a form as you simply put them back.
Thanks for the links

Thanks, will explore