[Solved] Running a script from a button

Creating and using forms
Post Reply
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

[Solved] Running a script from a button

Post by gkick »

Hello,

In order to strip the db of testdata and reset counters etc I use a textfile containing multiple SQL Statements
while the copy/paste into Tools/SQL works fine, I do not seem to be able to run this from a button but it also works fine when run from the macro window.

Any ideas what I am doing wrong here?

:?
Attachments
run via button
run via button
run via Tools, SQL or from Macro edit window
run via Tools, SQL or from Macro edit window
Last edited by gkick on Fri Sep 27, 2019 5:56 pm, edited 1 time in total.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
FJCC
Moderator
Posts: 9274
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Running a script from a button

Post by FJCC »

I am not familiar with Base macros but perhaps ThisComponent does not refer to the intended object when you run the code from the button. You can use the extension MRI to inspect what ThisComponent is in each case. There is a tutorial about MRI.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Running a script from a button

Post by Villeroy »

viewtopic.php?f=21&t=95587
Install the Python macro
Create a spreadsheet
Add a named cell "DB_Name" and enter the registered name
Add a named cell "SQL_Statement" and enter your DELETE statements separated by semicolons in correct order of dependencies (foreign keys before primary keys).
The macro to be called is "My Macros" > pyDBA > ParamsFromSheet > Main

A chain of DELETE statements does not require any further setup.
Last edited by Villeroy on Fri Sep 27, 2019 4:06 pm, edited 1 time in total.
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
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: Running a script from a button

Post by gkick »

Thank you, will check it out.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
UnklDonald418
Volunteer
Posts: 1547
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Running a script from a button

Post by UnklDonald418 »

Try using the Approve Action event for the Button to get the active connection

Code: Select all

sub runcleanup (oEv as Object)

oDoc = oEv.Source.Model
While oDoc.ImplementationName <> "com.sun.star.comp.dba.ODatabaseDocument"    
  oDoc = oDoc.Parent
Wend

REM  now get active connection
 oConn =   oDoc.CurrentController.ActiveConnection
 oStatement = oConn.createStatement()
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
gkick
Posts: 324
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: Running a script from a button

Post by gkick »

Thank you all for your help, changing the event to Approve Action did do the trick, thats great !!!!
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Running a script from a button

Post by Villeroy »

The screenshot indicates that the macro to be run is embedded in the database document. Replace ThisComponent with ThisDatabaseDocument which refers to the containing database document from the view point of any embedded object.
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