[Solved] SQL update in macro

Discuss the database features
Post Reply
bandoro
Posts: 22
Joined: Tue Oct 18, 2011 8:24 am

[Solved] SQL update in macro

Post by bandoro »

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
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
RPG
Volunteer
Posts: 2261
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: sql update in macro

Post by RPG »

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
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
bandoro
Posts: 22
Joined: Tue Oct 18, 2011 8:24 am

Re: sql update in macro

Post by bandoro »

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
The greatest gift you can give is share your knowledge to others
Windows 7 HOME 64 BIT, Openoffice 3.3
RPG
Volunteer
Posts: 2261
Joined: Tue Apr 14, 2009 7:15 pm
Location: Netherlands

Re: sql update in macro

Post by RPG »

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
LibreOffice 24.8.5.2 on openSUSE Leap 15.6
rudolfo
Volunteer
Posts: 1488
Joined: Wed Mar 19, 2008 11:34 am
Location: Germany

Re: sql update in macro

Post by rudolfo »

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.
bandoro
Posts: 22
Joined: Tue Oct 18, 2011 8:24 am

Re: sql update in macro

Post by bandoro »

Finally I manage to write the code and work perfectly

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
Now i know how write SQL in macro :D

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
Post Reply