I have a Linux Mint OS on an AMD system with a MySql db direct connected to LO Base. I am working on a business Point of Service app using desktop software. Specifically the Basic Macro / SQL query I am working on will be to add tasks to a customer record. The tasks are made up of the labor and the parts. I am trying to run a workable query in a macro as LO Base doesn’t allow “Insert Into” processes. I found a macro code example for OO, but it doesn’t work for my query as I get an error at the first or second ". This query does also work within Base Tools/SQL. Below is the snippet I adopted and am working with:
REM ***** BASIC *****
Sub Insert2TblInvoice
REM INSERT RECORDS INTO DATABASE TABLE
Dim Context
Dim DB
Dim Conn
Dim Stmt
Dim Result
Dim strSQL As String
Context=CreateUnoService("com.sun.star.sdb.DatabaseContext") '< get the database context
DB=Context.getByName("autopos.ActivInv") '<- change database name
Conn=DB.getConnection("","") '<- username & password pair - HSQL default blank
Stmt=Conn.createStatement()
strSQL="INSERT INTO "autopos"."TblInvoices"
(InvoiceNo
, `Group`
, TaskDscrp
, LabrTime
, TaskRetail
, StockNo
, PartNo
, PartDscrp
, PartsQty
, Retail
, TParts
, GTotal)
(Select
InvoiceNo
, t1.`Group`
, t1.TaskDscrp
, t1.LabrTime
, (t1.LabrTime * 60.00) as TaskRetail
, t1.StockNo
, t1.PartNo
, t1.PartDscrp
, t1.PartsQty
, t1.Retail
, (t1.PartsQty * t1.Retail) as TParts
, (t1.PartsQty * t1.Retail) + (t1.LabrTime * 60.00) as GTotal
From autopos. ActiveInv t1
)" '<- change tablename, column name/s and data to be inserted
Stmt.executeUpdate(strSQL) '<- update the inserted data
Conn.close() '<- close the db connection
End Sub
The SQL code above is the working SQL. I have removed my botched versions where I tried “” on the table and vars. None of which worked. I have read the LO 6 Guide for Macro as well as the “AndrewMacro” document, which none address SQL in a Macro. I have exhausted my resources and this is the first time I have asked for help on anything computer related since 1989. Assistance would be appreciated.