Two errors into one msgbox

Sup, I have a table DBColor, that have the IDColor and Color columns, both columns are set to unique. I created a form where the user can enter a new color in a combobox.

An example, if the color white is already on the table, when the user tries to write white in the combobox, base returns a msgbox containing the errors, errors in the plural because there are 2 that happen.

The first one is because the register was unable to be saved, and the second one is because the table doesnt accept duplicate values on the column Color, but libreoffice base translate this two errors, in only one msgbox, that closes when you click ok, but this doesnt apply when I try to write a macro to handle the errors better, by putting more cohesive information for the user on the msgbox.

I’m putting the macro inside the form control on the error ocurred event, but it turns out that here the two errors are divided, the macro run for the first error, and then again for the second error, so the user have to click ok two times for the same message, what is kinda annoying.

What I would like to have is something like the default error that base shows, but with a different text inside it, so I can keep things more clear for the user, or a way to put this two errors together, so the user receive only one msgbox, I need this since Im not the one who will be using this DB.

This is the macro im using, its pretty simple:

REM  *****  BASIC  *****

Sub ERRORMSG

MsgBox "The value added is already on the table, please try again with a new value.", , "Error"
    
end sub

If you want to work with macros: Why do you allow to write text into a combobox? I would prefer listboxes. So one could even chose values, which are allowed to chose. You could set the allowed values for the listbox by macro if listboxes are standalone listboxes (not inside a table control).

I need the user to input these values, because I dont know what colors of cars he will need to add. He need to add them so that he can use it in the main form, to fill the information about the car.

If you upload the example you described, then I think we can find a solution.

Got just the same problem.
The event appears two time. First for the FormController, then for ODatabaseForms. Solved it this way:

SUB DeleteError(oEvent AS OBJECT)
	oForm = oEvent.Source
	IF hasUnoInterfaces(oForm, "com.sun.star.form.XForm" ) THEN
		stMessage = "Deletion not possible."
		msgbox (stMessage, 64, "Deletion Error")
	END IF
END SUB

You could get the the message, which appears by default, with oEvent.Reason.Message, and if there are more details: oEvent.Reason.NextException.Message.

1 Like

I think that settles it, what event did you input this macro in?

I took this event. If there is any macro code connected to this event no error will be shown any more …