Hi there,
i've been around this problem for 3 days now
i need to know how to proper way to write sql update with in macro?
UPDATE tablename SET tablefield = variable1 WHERE tablefield = variable2
Variable1 and variable2 is a value from form.
i seen many examples in the forum but i've still know idea where to put quote (") mark and what is _& stand for ??
Thanks
[Solved] SQL update in macro
[Solved] SQL update in macro
Last edited by bandoro on Thu Dec 15, 2011 10:46 am, edited 1 time in total.
The greatest gift you can give is share your knowledge to others
Windows 7 HOME 64 BIT, Openoffice 3.3
Windows 7 HOME 64 BIT, Openoffice 3.3
Re: sql update in macro
Hello
Before you start with macros test the SQL in the SQL tool. Then you can be sure you have no more problems in the SQL code.
Romke
Before you start with macros test the SQL in the SQL tool. Then you can be sure you have no more problems in the SQL code.
Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
Re: sql update in macro
already done that and success but without variable
in sql tool i write : UPDATE "Tablename" SET "Column1"='String1' WHERE "Column2"='String2'
where String1 and String2 is a string value not a variable value from form
in sql tool i write : UPDATE "Tablename" SET "Column1"='String1' WHERE "Column2"='String2'
where String1 and String2 is a string value not a variable value from form
The greatest gift you can give is share your knowledge to others
Windows 7 HOME 64 BIT, Openoffice 3.3
Windows 7 HOME 64 BIT, Openoffice 3.3
Re: sql update in macro
Hello
The next step you must make a macro for starting up The SQL code.
What code you have now and how do you start the macro. What I now see does not look as the orginal code you test in the SQL line for some reason I do want see now the SQL code.
Romke
The next step you must make a macro for starting up The SQL code.
What code you have now and how do you start the macro. What I now see does not look as the orginal code you test in the SQL line for some reason I do want see now the SQL code.
Romke
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
Re: sql update in macro
Maybe you have a look at this thread Need help with another tricky query. The last post has an example how to work with an update after a click on a button.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Re: sql update in macro
Finally I manage to write the code and work perfectly
Here is the code :
Now i know how write SQL in macro
Thanks for all your support
Here is the code :
Code: Select all
Sub Pushbuttontest (oEvent as object)
Dim oForm, oCon, oCoba, oID, oSql as object
Dim oSqlstring as string
oForm = oEvent.Source.Model.Parent
oCon = oForm.ActiveConnection
oCoba = oForm.getbyname("Testnew") 'Textbox where i write new value
oID = oForm.getbyname("IDbox") 'Textbox where i Display Current ID from the Table Tabletest (ID is integer with autovalue)
msgbox oID.currentvalue ' optional
msgbox oCoba.text 'optional
oSql = oCon.CreateStatement()
oSql.executeupdate("UPDATE ""Tabletest"" SET ""Test"" = '"& oTestnew.text &"' WHERE ""ID"" = '"& oID.text &"'")
End sub

Thanks for all your support
The greatest gift you can give is share your knowledge to others
Windows 7 HOME 64 BIT, Openoffice 3.3
Windows 7 HOME 64 BIT, Openoffice 3.3