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

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.

@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 may have been just my ignorance.
On top running reports from a free standing form ??? So I gave up.

cheers
Gerhard

@gkick,

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).

@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…

@gkick,

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())

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.

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.

@gkick,

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" )

@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.

Weather about the same as yours.

@Ratslinger Have added

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.

Sorry, cannot help without sample. There seems yet to be a library not loading. Should be no reason to have a workaround.

Edit:

It just occurred to me, this is not clear. Are you referring to standalone forms or regular Base? Your previous comments could be either.

Possibly this should be an entirely new question.

@Ratslinger
Have posted new question Macro not firing

Hello @Ratslinger ! Thanks for the interesting code.
We can try:

  • open a form (or report) of a document for editing in hidden mode
  • save and close without prompting the user.

The attached example dynamically creates a listener for the OnLoad event of the Form1 document.

Option Explicit

Sub Test4
  Dim oSubDoc, oFormDoc, oDBDoc, formName As String
  Dim oProps(1) as new com.sun.star.beans.PropertyValue 
  Dim oProps2(0) as new com.sun.star.beans.PropertyValue 
  
  formName="Form1"
  oDBDoc=ThisDatabaseDocument
  oSubDoc = oDBDoc.FormDocuments.getByName(formName)
  'oFormDoc = oSubDoc.openDesign()
  oProps2(0).Name = "Hidden"  : oProps2(0).Value = True
  oDBDoc.CurrentController.Connect
  oFormDoc = oDBDoc.CurrentController.loadComponentWithArguments(2, formName, True, oProps2())  ' open Form for editing (hidden)
  
  With oFormDoc
    oProps(0).Name = "EventType"  : oProps(0).Value = "Script"
    oProps(1).Name = "Script"     : oProps(1).Value = "vnd.sun.star.script:Standard.Module1.OnLoad?language=Basic&location=document"
    .Events.replaceByName "OnLoad", oProps
  End With  
  
  oSubDoc.store()
  'oSubDoc.close()   ' Asks a question to the user
  oSubDoc.dispose
End Sub

Sub OnLoad(oEvent)
  Msgbox "Open Form: " & Chr(10) & oEvent.Source.Title
End Sub
1 Like

@sokol92
.
Thanks for the post. Have done similar in past.

1 Like