Page 1 of 1

[SOLVED] Button to enable/disable allow modification of data

Posted: Thu Jan 23, 2020 1:27 pm
by MHCom
Hi,

I have a simple form for viewing, modifying and adding new records to a table. Due to the way that forms work it's all too easy for someone to accidentally change some data on a record with realising they are doing it.

What I would like to make the form more secure and more user-friendly is the option to turn on and off the allow modifications setting for the form.

So what I thought would work is to have the form's default setting to not allow modifications, then have 2 push buttons: one to change the setting to allow modifications; a second button to save changes and then change the setting back to do not allow modifications.

I've tried recording a macro turning the allow modifications on and off but when I assign this to a push button, it does not work - nothing happens basically. I have the macro assigned to the "Mouse button pressed" event.

The macro code is:

Code: Select all

sub turnonmods2
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "FormProperties"
args1(0).Value = true

dispatcher.executeDispatch(document, ".uno:FormProperties", "", 0, args1())


end sub

Re: Button to enable/disable allow modifications to data

Posted: Thu Jan 23, 2020 2:32 pm
by Villeroy
[Tutorial] Introduction into object inspection with MRI
Mostly recorded with MRI with a toggle button's status-changed event:

Code: Select all

Sub Snippet(Optional oInitialTarget As Object)
  Dim nSelected As Long
  Dim oSource As Variant
  Dim oModel As Variant
  Dim oParent As Variant
  Dim bAllowUpdates As Boolean
  Dim bAllowInserts As Boolean
  Dim bAllowDeletes As Boolean
  nSelected = oInitialTarget.Selected
Dim bEnabled As Boolean
bEnabled = cBool(nSelected)
  oSource = oInitialTarget.Source
  oModel = oSource.getModel()
  oParent = oModel.getParent()
  
oParent.AllowUpdates = bEnabled
oParent.AllowInserts = bEnabled
oParent.AllowDeletes = bEnabled
  
End Sub

Re: Button to enable/disable allow modifications to data

Posted: Fri Jan 24, 2020 6:03 pm
by MHCom
I've tried your code in two ways:

When I assign it to the status change event of a toggle button and use the button, nothing happens.
When i assign it to the mouse button pressed event of a non-toggle button, I get the following error:

Basic run time error. Property or method not found: Selected

For the following code line:
nSelected = oInitialTarget.Selected

Re: Button to enable/disable allow modifications to data

Posted: Fri Jan 24, 2020 6:18 pm
by Villeroy

Code: Select all

oParent.reload()
is missing.

Re: Button to enable/disable allow modifications to data

Posted: Mon Jan 27, 2020 12:37 pm
by MHCom
Brilliant, that has done the trick! Thank you!

Re: [SOLVED] Button to enable/disable allow modification of

Posted: Mon Jan 27, 2020 1:14 pm
by MHCom
One more thing, how might I tweak this code so that it runs from a push button rather than a toggle button? Sorry, I can't find any guides online for code writing which is frustrating as I'd like to learn to do this myself.

Re: [SOLVED] Button to enable/disable allow modification of

Posted: Mon Jan 27, 2020 1:19 pm
by RoryOF
Code writing is covered in the OO BASIC manual at

https://wiki.openoffice.org/wiki/Docume ... ASIC_Guide

And longer, more complex code help at
http://www.pitonyak.org/OOME_3_0.odt
http://www.pitonyak.org/OOME_3_0.pdf

Re: [SOLVED] Button to enable/disable allow modification of

Posted: Mon Jan 27, 2020 1:52 pm
by Villeroy
If you are a programmer, the MRI tutorial and linked documentation is all you need. If you are not a programmer, you can't write macros anyway.