I have three fields and i want concatenate them in to a fourth field using macros with the option LostFocus. I think i can concatenate the text boxes with the same result. How can i do this? I’m new in LibreOffice Base. I’m using libreoffice 6.2 and windows 10
Hello,
Don’t see why you would need to do this. You are duplicating data. If the data is needed in a concatenated form for some purpose it can be done using SQL. For someone new to LO Base, macros are not intuitive. It requires a wide range of understanding.
For LO documentation see this post → LibreOffice Base Handbook. Aside from the chapter on macros there, you can find links to other macro documentation on this post → To learn LibreOffice Base are there introductions or tutorials?. In particular Open Office Macros Explained
by Andrew Pitonyak is most useful.
Please be aware, when asking questions, include the specific LO version you are using, your OS, and with Base the database you are dealing with. This information usually determines a direction to take or where the problem may reside. For example, different databases will differ in SQL capabilities and possibly syntax.
Edit:
Best way is to give sample. Here is code used:
Option Explicit
Sub ConcatFields
Dim oForm As Object
Dim sTextCompany As String
Dim sTextDepartment As String
Dim iNumberEmployee As String
Dim sResult As String
Rem get form
oForm = ThisComponent.Drawpage.Forms.getByName("MainForm")
Rem get control values
sTextCompany = oForm.txtCodeCompany.Text
sTextDepartment = oForm.txtCodeDepartment.Text
iNumberEmployee = oForm.fmtNumberEmployee.Value
Rem Concat fields
sResult = sTextCompany & "-" & sTextDepartment & "-" & iNumberEmployee
Rem move result to field
oForm.txtCodeEmployee.Text = sResult
Rem Commit data for field
oForm.txtCodeEmployee.commit
End Sub
One form in sample. Two text controls & one numeric control to show differences.
Also included a simple query demoing the same result without using macros.
Sample — ConcatFields.odb
You have amended your question but still no database specified (Base is NOT a database). A database is Firebird or HSQLDB embedded or MySQL or PostgreSQL etc. Also the answer still applies. Don’t see any reason to do what you are requesting. Maybe present one?
Also note, LostFocus
is not an option but rather an Event which is used to trigger a macro.
I’m using HSQLDB. I want to concatenate them because the fourth field is a code codeemployee=codecompany+codedepartment+numberemployee
LostFocus is an Event I know that from Ms Vb and Ms Acsess, but I do not code for more than 16 years because of a disease. I’m a quadraplegic writing with the mouth and i’m just a old timer stuck in LO Base Forms coding. I was just giving a try in LO Base.
I want to use LibreOffice Basic
Please see edit in answer. Also consider using Firebird embedded database. Better than HSQLDB after initial set up considerations.
It worked, now i understand what was my mistake. About Firebird i intended to use it but LO Base was crashing when using it. But i will give a try again. Thank you very much.