libreoffice - how to store database inside odt document

91 views Asked by At

I'm using libreoffice and I have a problem to create a list of data inside an odt document to use for a macro.

I see odt documents can store a database with keys and values, so I want to make a database to store inside the document.

The problem

I open an odt document and enter inside the data source menu trought View -> Data sources, I select tables and create a new database with use wizard to create table.

After I configure the database keys and select add data now I get this error:

error

The details of the error says this, I'm not using SQL nor I'm an expert about it so I don't know what is referring about.

SQL Status: HY000
The query cannot be executed. It contains no valid columns.

The SQL command leading to this error is:
SELECT * FROM "Tasks"

What I'm doing wrong?

I can't find anything online to solve this problem, all buttons on the database interface are disabled and I can't click anything useful.

How do I make this databse? and how do I access his data from a visual basic macro?

1

There are 1 answers

0
Jim K On BEST ANSWER

There's a rule of thumb followed by experienced users of Base: Avoid wizards! Here is what I did:

  1. Right-click on Tables > Edit Database File. Create Form in Design View.
  2. Column id integer, Column name varchar
  3. Save as Tasks. Also, save the Base and Writer files.

Now enter some data in the Data Sources view from Writer.

tasks table

Finally, here is a macro to display "build proposal" and "submit proposal".

oDatabaseContext = createUnoService("com.sun.star.sdb.DatabaseContext")
oDatasource = oDatabaseContext.getByName("Bibliography")
oConnection = oDatasource.GetConnection("","")
oSQL_Statement = oConnection.createStatement()
stSql = "SELECT * FROM ""Tasks"""
oResult = oSQL_Statement.executeQuery(stSql)
While oResult.next
    MsgBox oResult.getString(2)
Wend