stop form closing

Is there a way to force a form to stay open if someone clicks the close button and a condition is not true. For example if I checked for a condition of the onClose trigger of the form can I then say if this is not true then keep the form open.

Use the OnQueryCloseForm trigger’s return value.