[Solved] Running a script from a button

Creating and using forms

[Solved] Running a script from a button

Postby gkick » Fri Sep 27, 2019 9:47 am

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
runFromButton.JPG
run via button
runOk.JPG
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
gkick
 
Posts: 263
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: Running a script from a button

Postby FJCC » Fri Sep 27, 2019 2:43 pm

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.
Windows 10 and Linux Mint, since 2017
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
FJCC
Moderator
 
Posts: 7751
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Running a script from a button

Postby Villeroy » Fri Sep 27, 2019 4:05 pm

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

Re: Running a script from a button

Postby gkick » Fri Sep 27, 2019 4:06 pm

Thank you, will check it out.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
gkick
 
Posts: 263
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: Running a script from a button

Postby UnklDonald418 » Fri Sep 27, 2019 5:09 pm

Try using the Approve Action event for the Button to get the active connection
Code: Select all   Expand viewCollapse view
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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1326
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Running a script from a button

Postby gkick » Fri Sep 27, 2019 5:55 pm

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
gkick
 
Posts: 263
Joined: Wed Aug 07, 2019 5:24 pm
Location: Chile

Re: Running a script from a button

Postby Villeroy » Fri Sep 27, 2019 5:56 pm

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


Return to Forms

Who is online

Users browsing this forum: No registered users and 3 guests