Base Form: How to make one input field mandatory if the value entered in another field is less than zero

I have multiple fields in the form entry.
In one field, I can enter either a positive value or a negative value.
If I enter a negative value, the next field should become mandatory.

Can anyone please guide me on how to achieve this requirement? Thanks a lot in advance.

This would require a macro to check the value of your field on exiting that field for the negative value. If negative then set the InputRequired parameter to True:

  oObj2 = oObj1.getByName("YOUR_FIELD_NAME")
  bInputRequired = oObj2.InputRequired
  oObj2.InputRequired = True

You need to be aware that this was an old bug recently revived & newly implemented in LO v7.4.1.2
See tdf#150577

1 Like

In one still needs to have the table field set to not null for the InputRequired of the form to work.

1 Like

If you see the bug @Ratslinger has been linked to: LO and also LO will work well. Older version won’t do anything with set input required only in the form.

1 Like

Thanks for your response. Have now upgraded to Would you please provide some detailed steps of how to accomplish this as this looks promising.

With code it depends upon what you have set in your form, especially control names. Do you have any macro experience? Have you looked at the documentation for this?
If you want, I can attach a sample but you will need to translate to your Base file. Or, you can attach your Base file and I will modify for you. However, there concern then is if you are not experienced, how are you going to maintain in the future when modifications are needed?

1 Like

Thanks @Ratslinger for your quick response.
If you can please attach a sample, I will try to translate to the base file.

Appears there may be a further problem to this fixed Bug. Upon entering an incorrect Value which sets the requirement, if you go to correct the requirement is still there.
Need to check further.
Also, you did not answer my questions from the comment.

Thanks @Ratslinger - I will try to answer all your questions.

  1. I have experience in MS Excel Macros
  2. I have not looked at the Base Macro Documentation. If there is any, willing to go through it.
  3. I am not sure how to attach MY base file without data for your help to fix it.

Thanks for your help and guidance

ALTER TABLE "tbl" ADD CONSTRAINT "MinusPlus" CHECK (("number"<0 AND NOT "next" IS NULL)OR "number">=0)

Here is a sample with a different macro. Checks the value when record change is requested (Before record action event of form):

MandatoryFieldBasedUponValue.odb (13.7 KB)

For documentation see:

and search for macros. Also see:

And for posting a sample, there is a toolbar icon when posting. See:

Your statement works in HSQLDB embedded only if you remove the quote marks from the constraint name. Otherwise it thinks it is a field name.

The following generates a valid database table with constraints. When you violate the constraint, you get the regular SQL error message. The upper-case name “B_NUMBER_MISSING_FOR_NEGATIVE_A” stands out, so the user gets a hint about the reason. [I gave up on SQL error handlers and triggers]


This is the database created by the above statements.
MinusConstraint.odb (3.2 KB)