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

Creating and using forms
Post Reply
MHCom
Posts: 16
Joined: Fri Nov 08, 2019 4:55 pm

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

Post 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
Last edited by robleyd on Mon Jan 27, 2020 12:53 pm, edited 2 times in total.
Reason: Add green tick
OpenOffice 4.1.5 on Windows 7 Professional
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Button to enable/disable allow modifications to data

Post 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
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
MHCom
Posts: 16
Joined: Fri Nov 08, 2019 4:55 pm

Re: Button to enable/disable allow modifications to data

Post 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
OpenOffice 4.1.5 on Windows 7 Professional
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Button to enable/disable allow modifications to data

Post by Villeroy »

Code: Select all

oParent.reload()
is missing.
Attachments
blah.odt
(11.88 KiB) Downloaded 223 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
MHCom
Posts: 16
Joined: Fri Nov 08, 2019 4:55 pm

Re: Button to enable/disable allow modifications to data

Post by MHCom »

Brilliant, that has done the trick! Thank you!
OpenOffice 4.1.5 on Windows 7 Professional
MHCom
Posts: 16
Joined: Fri Nov 08, 2019 4:55 pm

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

Post 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.
OpenOffice 4.1.5 on Windows 7 Professional
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Post 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
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Post 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.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply