Writing result from macro to textbox on form

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
krtica
Posts: 1
Joined: Sun Nov 23, 2008 1:52 pm

Writing result from macro to textbox on form

Post by krtica »

I wanna to make macro in base, which will get data from random record from table and put it in textboxes.
I never used macros before.
I googled a lot, and I was able to write this:

Code: Select all

Sub Main
DBContext=createUnoService("com.sun.star.sdb.DatabaseContext")
 If not DBContext.hasByName("testdb") then
   MsgBox ("Connection failed!" , "Error!") : End
 End If
DataSource=DBContext.getByName("testdb")
ConnectToDB=DataSource.GetConnection ("","")
SQLResult=createUnoService("com.sun.star.sdb.RowSet")
SQLQuery="SELECT ""ID"", ""JBRTR"", ""OZB"" FROM ""testtable"""
SQLResult.activeConnection=ConnectToDB
SQLResult.Command=SQLQuery
SQLResult.execute
SQLResult.Last
Rows=SQLResult.getRow
Do
 RandomID=Int(Rnd()*Rows)
 SQLResult.Absolute(RandomID)
 JeBrTrans=SQLResult.getString(2)
 OzBa=SQLResult.getString(3)
Loop While isEmpty(JeBrTrans)
msgBox( JeBrTrans & " , " & OzBa )
ConnectToDB.close
ConnectToDB.dispose()
End Sub
I assigned this macro to button, and when I click on it I'm getting msgBox with wanted results.

But I'm TOO STUPID to put those results in textBoxes on same form from where I click on Button.
I really tried to do it myself, but without any success.
So, if anyone is merciful enough to tell me what is exact code I'm unable to figure out.

Thank you. Thank you very much.
OOo 3.0.X on Ubuntu 8.x + Windows XP
User avatar
Hagar Delest
Moderator
Posts: 32664
Joined: Sun Oct 07, 2007 9:07 pm
Location: France

Re: Writing result from macro to textbox on form

Post by Hagar Delest »

Moving the thread to the Macro forum.
LibreOffice 7.6.2.1 on Xubuntu 23.10 and 7.6.4.1 portable on Windows 10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Writing result from macro to textbox on form

Post by Villeroy »

No macro required. Just create an ordinary form bound to

Code: Select all

SELECT TOP 1 "ID", "JBRTR", "OZB" FROM "testtable" ORDER BY Rand()
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply