# How to change Form Properties With Code

WIN 10 LO 6.7.2 HSQL2.51

Hi,

One can easily change form properties such as entry only, no delete etc from inside the property listing. Can the same be done via code attached to an event or perhaps even better from outside the form to prevent accidental modifications as I do not think there is a way of disabling access to the design view.

Freestanding forms do not seem to be a viable option as multiple connection problems once a form has multiple datasources.

Thanks

edit retag close merge delete

Sort by » oldest newest most voted

Hello,

This can be done by editing the form. Would possibly want to add code to open the form minimized. Start of code here is based upon execution from Main Base screen. Need to modify depending upon where this is executed from.

oObj1 = ThisDatabaseDocument.FormDocuments.getByName("EXTERNAL_FORM_NAME")
oObj2 = oObj1.openDesign()
oDrawPage = oObj2.getDrawPage()
oForms = oDrawPage.getForms()
oObj3 = oForms.getByName("INTERNAL_NAME")
oFrame = oObj2.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
Rem Changes here - oObj3 is Form - Wait is here for test - need time for form to open
Wait 1500
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Value = 0
dispatcher.executeDispatch(oFrame, ".uno:Save", "", 0, args1())
oObj1.close()


Will also need code to save Base since this is modifying a form in the file. Code will vary depending upon where run from. Similar to dispatch code already presented.

Don't really understand this statement in question:

Freestanding forms do not seem to be a viable option as multiple connection problems once a form has multiple datasources.

more

@Ratslinger

Hi and thanks, hope you are well...

Are the args(0) sequential in line with the dialog, so eg Allow additions would be

dim args1(6) as new com.sun.star.beans.PropertyValue


args1(6).Value = 1 for no dim args1(7) as new com.sun.star.beans.PropertyValue args2(7).Value = 1 for no

Re freestanding forms, well the real trouble is that the database container is completely open and so far I ve only learned that you can minimize it, there is some French code to actually hide it which seems to make macros unusable.

So experimented a couple of times with free standing forms which contained several table controls based on queries and tables. The form then displayed multiple authentication requests. Also found not being able to build a to from interface between forms s as there only seems to be one hyperlink property, but that ...(more)

( 2021-01-08 02:06:22 +0100 )edit

The arguments have nothing to do with any dialog. If recalling correctly, this argument is to set return of control after the close.

It appears you are trying to secure the application. About the best security available is to password protect the macros. Other than that it is fairly simple (need some knowledge of internals) to override things. I believe there is at least one open request to add password protection at some level(s).

( 2021-01-08 02:30:35 +0100 )edit

@Ratslinger yes I use password protected macros, at times they execute from direct run but not when called from Cusomize, Open Doc, sometimes they do work by attaching them to the on activate event if I want to run them from the db container to do some db manipulation stuff, still learning...

( 2021-01-08 02:48:14 +0100 )edit

Further testing shows no argument is needed. You can replace this part:

dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Value = 0
dispatcher.executeDispatch(oFrame, ".uno:Save", "", 0, args1())


with just this:

dispatcher.executeDispatch(oFrame, ".uno:Save", "", 0, ARRAY())

( 2021-01-08 05:36:53 +0100 )edit

Thanks for that, Guess one can sort of bury the actual hidden macro within other macros to make it harder to detect or remove but then ultimate security is a dream, isn it.

( 2021-01-08 05:59:51 +0100 )edit

To further clarify, here is link to arguments for unoSave -> The UNO Dispatch Command Specifications of '.uno:Save' .

My earlier comment I confused with something else.

( 2021-01-08 06:09:44 +0100 )edit

Had not tested in a while so did some basic tests with PW protected macros. Had no problem with execution from a button or direct execution from the menu. Don't know where your problems reside but may have something to do with loading libraries. This really depends on where & how you have set code & in what libraries they exist. Example:

Globalscope.BasicLibraries.LoadLibrary( "YOUR_LIBRARY" )

( 2021-01-08 22:42:23 +0100 )edit

@Ratslinger , thanks again. Well my problem seems to be when calling the pw macro from the db containers customise open doc event. It runs from the activate and closing events where it for some reason is triggered more then once. I ll check out loading the globalscope What are the temperatures like in your neck of the woods ? Here sunny 24c.

( 2021-01-08 23:16:38 +0100 )edit

Weather about the same as yours.

( 2021-01-08 23:19:29 +0100 )edit

If GlobalScope.BasicLibraries.hasByName("sm12") Then GlobalScope.BasicLibraries.loadLibrary("sm12") End If

to the setup macro which connects to the backend and establishes connection to the db, but does not make a difference.

Just need to run some validation prior to opening the mainform. Workaround is to pop up a splashform first, run the macro from there and close the splash, open the mainform.

( 2021-01-08 23:49:47 +0100 )edit

## Stats

Asked: 2021-01-07 23:20:21 +0100

Seen: 16 times

Last updated: Jan 08