On 08/28/2014 07:46 AM, Allan Newton wrote:
In a database of mine a very convenient way to execute some operations is by
running a small series of SQL statements.
As Base has no direct way to run a text file of SQL statements I asked on
Ask Libre Office and was given code in Basic that would read and execute a
file of SQL.
The first few lines of code are shown below
REM ***** BASIC *****
rem Option Explicit
Sub DoSQL
rem how to read text file
rem https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=33009
rem how to execute sql
rem
http://ask.libreoffice.org/en/question/21205/libreofficebase-how-to-execute-
sql-from-basic-script/
rem check database connection
DIM txtfile AS STRING
DIM f1 AS INTEGER
DIM s AS STRING
DIM oStatement AS OBJECT
MsgBox("Code started")
if IsNull(ThisComponent.CurrentController.ActiveConnection) then
ThisComponent.CurrentController.connect
endif
If I run this from the macro menu it runs perfectly.
However if I create blank form with just one button and set the properties
of that button to
run the macro it fails at the line
if IsNull(ThisComponent.CurrentController.ActiveConnection) then
with the error message
"BASIC runtime error.
Property or method not found: ActiveConnection."
Can anyone help me please?
My final objective would be a form with 3 or 4 buttons each of which would
execute a different file of SQL
Regards
Allan
__
Allan Newton
Optical System Design
I assume that you have read this:
https://forum.openoffice.org/en/forum/viewtopic.php?f=45&t=67139
I have not looked at this stuff in a long time, but, here are a few
thoughts off hand.
1. The error is stating that the "ActiveConnection" property is not
available from the current controller for the current document. So, what
is different with respect to the current document when you run this from
a "form" compared to running this from an event handler? Again, I am
just guessing, but... is the form part of a Base document? If it is,
then you may need to grab the parent containing Base document, but that
is a straight up guess. Do you know that you have an active connection?
I think that this leads directly back into the link above related to
ThisDatabaseDocument compared to ThisComponent.
Another possibility is that you test the current controller to see if it
supports the ActiveConnection property. The fact that you test to see if
the ActiveConnection is null, tells me that if you suspect that it may
not contain one. I assume that you do something like this if needed:
oBaseContext = CreateUnoService("com.sun.star.sdb.DatabaseContext")
oDataBase = oBaseContext.getByName(sDBURL)
oCon = oDataBase.getConnection("", "")
At one point, I even did something silly like this inside of an event
handler (not that I know if that would work for your or if it would
still work):
oCon = oEvent.Source.Model.Parent.ActiveConnection
container = oCon.Parent.DatabaseDocument.FormDocuments
I hope this helps a little.
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
Info: http://www.pitonyak.org/oo.php
--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette
List archive: http://listarchives.libreoffice.org/global/users/
All messages sent to this list will be publicly archived and cannot be deleted
Context
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.