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?
[Solved] Running a script from a button
[Solved] Running a script from a button
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
Re: Running a script from a button
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.
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Re: Running a script from a button
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.
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Re: Running a script from a button
Thank you, will check it out.
Libre Office 6.4.6 on Windows 10 HSQL 2.51 backend
-
- Volunteer
- Posts: 1547
- Joined: Wed Jun 24, 2015 12:56 am
- Location: Colorado, USA
Re: Running a script from a button
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
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Re: Running a script from a button
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
Re: Running a script from a button
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
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice