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

Creating and using forms

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

Postby MHCom » Thu Jan 23, 2020 1:27 pm

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   Expand viewCollapse view
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
MHCom
 
Posts: 16
Joined: Fri Nov 08, 2019 4:55 pm

Re: Button to enable/disable allow modifications to data

Postby Villeroy » Thu Jan 23, 2020 2:32 pm

[Tutorial] Introduction into object inspection with MRI
Mostly recorded with MRI with a toggle button's status-changed event:
Code: Select all   Expand viewCollapse view
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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28351
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Button to enable/disable allow modifications to data

Postby MHCom » Fri Jan 24, 2020 6:03 pm

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
MHCom
 
Posts: 16
Joined: Fri Nov 08, 2019 4:55 pm

Re: Button to enable/disable allow modifications to data

Postby Villeroy » Fri Jan 24, 2020 6:18 pm

Code: Select all   Expand viewCollapse view
oParent.reload()
is missing.
Attachments
blah.odt
(11.88 KiB) Downloaded 21 times
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28351
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Button to enable/disable allow modifications to data

Postby MHCom » Mon Jan 27, 2020 12:37 pm

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

Postby MHCom » Mon Jan 27, 2020 1:14 pm

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
MHCom
 
Posts: 16
Joined: Fri Nov 08, 2019 4:55 pm

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

Postby RoryOF » Mon Jan 27, 2020 1:19 pm

Apache OpenOffice 4.1.7 on Xubuntu 18.04.4 (mostly 64 bit version) and very infrequently on Win2K/XP
User avatar
RoryOF
Moderator
 
Posts: 31105
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

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

Postby Villeroy » Mon Jan 27, 2020 1:52 pm

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, no OpenOffice, LibreOffice 6.4
User avatar
Villeroy
Volunteer
 
Posts: 28351
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany


Return to Forms

Who is online

Users browsing this forum: No registered users and 2 guests