Libreoffice forms fields value comparison

Hi all,
I am new to Libreoffice.
Backend Mysql.
two tables “IDs” “Family”.
Both tables are joined by Fields Ids.ID and Family.F_ID.
How do I compare these two fields value via VB scfripts in the form?
I have a micro via vb script that doesn’t work:

Sub Main
if “form::ids:ID” = “form::family:F_ID” then

MSGbox (“correct”)
else
MSGbox(“Not Correct”)
end if
End Sub

Thanks in advance for any help,

Abrahim

First you need to access to the forms: Base Guide - access to forms
Then you could connect to the element: Base Guide - accessing form elements
You could also use the form for directly connect to the datasource: Base Guide - connect to datasource

Don’t know anything about VB. Have only created macros for Base with Star Basic.

Hi Robert,

Thanks for the useful information.
Neither am I familiar with VB and looking for the easiest way to do that form’s field comparancen. Do you have any other way of doing that?

Thx-Abrahim

Why do you need to compare the foreign-key with the key? In a “normal” form table “Ids” and “Family” will be connected by mainform and subform. So you navigate through “Ids” and see the comapred values of “Family”.

An example will be helpful to see, which construction of the form you are using.

Hi Robert,

What I am trying to do is the double-entry process:
Here are the steps:
First user enters data into the Family Form"Table name Family", then
the second user enters data into the Family2 which is a temp form to make side by side data validation.
If all data match then confirm match data, else popup dialog informing user about the wrong data entry in the field.

I hope this helps.

Thx-Abrahim

You want to work with 2 forms, both opened in the same *.odb-file?

SUB Main
oFormDoc = ThisDatabaseDocument.FormDocuments.getByName( "Formname in Base" )
oForm1 = oFormDoc.drawpage.forms.getByName("MainForm")
oForm2 = ThisComponent.drawpage.forms.getByName("MainForm")
stString1 = oForm1.getByName("NameOfControl in Form1").BoundField.Text
stString2 = oForm2.getByName("NameOfControl in Form2").BoundField.Text
IF stString1 = stString2 THEN
MSGbox ("correct")
ELSE
MSGbox("Not Correct")
END IF
END SUB

With oForm1 you get the form, which should be connected to from oForm2. Both have a field, which should contain a string. The code above will show how to get the string and compare.

I’m not sure I have understood it the right way…

which form name should I write in “Formname in Base”?:
oFormDoc = ThisDatabaseDocument.FormDocuments.getByName( “Formname in Base” )

Thx

Formname in Base → its the name of the form document when you open Base. Or: The name of the form, which is opened by the person, which doesn’t start the macro.

The macro would be started by the person, who opened another form and want’s to compare. “MainForm” is the default, if you created forms by the wizard. If you haven’t created it by the wizard: Have a look at the name of the form by the form navigator.

Term “form” is a little bit confusing: There is a form document. If you open this document there is also a form in the drawpage of the document…

Robert,

I have 3 forms :IDS
Family
Family2
The micro is triggered when the value changes in Family2 Field “L_Name”.
But I get the following error;

BASIC runtime error.
An exception occurred
Type: com.sun.star.container.NoSuchElementException
Message: IDS.

here is the script:
/////////////////////////////
SUB Main

DIM oFormDoc as object

oFormDoc = ThisDatabaseDocument.FormDocuments.getByName( “IDS” )

oForm1 = oFormDoc.drawpage.forms.getByName(“Family”)

oForm2 = ThisComponent.drawpage.forms.getByName(“Family2”)

stString1 = oForm1.getByName(“L_Name”).BoundField.Text

stString2 = oForm2.getByName(“L_Name”).BoundField.Text

IF stString1 = stString2 THEN

MSGbox (“correct”)

ELSE

MSGbox(“Not Correct”)

END IF

END SUB

/////////////////////////

all 3 forms are open and active while the micro runs.

Thx-Abrahim

“IDS” → This will be the name of the form document in Base.
“Family” → This will be the form inside the form document “IDS”.
“Family2” → This will be the form inside another form document.

Please add the database here (without your personal data). So I could have a look what is going wrong.

Robert,

The database name is:

EBIDB

Thx

screenshot of forms

There is no download for the form available. But the screenshot says:

oFormDoc = ThisDatabaseDocument.FormDocuments.getByName( “EBIDB.IDS” )

This will be the name of the form document. Now open this form document and start the form navigator. Which is the name of the form inside this form document? This should be the entry for oForm1.

Seems you don’t see the difference between the form document (all in your database start with “EBIDB.”) and the forms inside this document. Think the names for oForm1 and oForm2 are also wrong. “EBIDB.IDS” is the first form you opened. No other form document name is needed.

Would be better you contact me per private mail. See impressum fo my homepage.

Robert,

I don’t see any email on your website. Can you provide your email to me?