Hi Robert,
the thought occurs to me that the existing quotes within the SQL
statements may need their own treatment. The statements that work under
the LOBase Tools>SQL... function have different type of single
quotemarks for the column names (e.g. containing two separate words) or
the text to be set in the columns. I have assumed that the macro (SQL)
string variables just need to be enclosed in double quotemarks. Is this
right?
Cheers
Harvey
On Wed, 2023-01-25 at 21:51 +0100, Robert Großkopf wrote:
Hi Harvey,
how would this work for me, where I only want to create a SQL
statement
as a string and execute it.
Mcro works with SQL-code, which has been saved in a field of a table.
Field in the table is called "SQL-Code". Table is datasource of a
form.
A button in this form will start the code.
First needed object is executing a button in the form to start the
procedure.
If you will save all code directly in a macro you will need
→ a connection to the database
→ SQL code, which has been maskes with double doublequotes for
fieldnames and tablenames
→ var for creating a statement
→ execute the sql-code in this created statement
At which line of the macro the code stops for you?
Here a code from German Base Handbuch:
SUB ChangeData(oEvent AS OBJECT)
DIM oConnection AS OBJECT
DIM oForm AS OBJECT
DIM stSql AS STRING
DIM oSql_Statement AS OBJECT
DIM inValue AS INTEGER
oForm = oEvent.Source.Model.Parent
oConnection = oForm.activeConnection()
stSQL = oForm.getString(oForm.findColumn("SQL-Code"))
inValue = MsgBox("Should SQL-Code" & CHR(13) & stSQL & CHR(13)
&
"be executed?", 20, "Execute SQL-Code")
IF inValue = 6 THEN
oSQL_Statement = oConnection.createStatement()
oSQL_Statement.execute(stSql)
END IF
END SUB
SQL-Code is part of a table. Field in the table is "SQL-Code".
Table
is
datasource of a form. A button in this form will be enough to
execute
the macro. You coud update, insert or delete rows by command
"execute".
Regards
Robert
--
Homepage: https://www.familiegrosskopf.de/robert
--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy
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.