Redirect when 'No Record Found'

I have a search app that calls a form and it’s connected to the form by two variables. if the search result’s empty it send nothing to these two variables thus the form app comes with an error:

Error while accessing the database:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘order by xts_sub_authorisation_statuses.END_DATE DESC LIMIT 0,7’ at line 2

Select Limit
(SELECT xts_sub_authorisation_statuses.ID as cmp_maior_30_1,
xts_cards.CARD_NO as xts_cards_card_no,
xts_sub_authorisation_statuses.BEGIN_DATE as cmp_maior_30_2,
xts_sub_authorisation_statuses.END_DATE as cmp_maior_30_3,
(case EVENT_TAG when ‘69633’ then ‘Satelitor’ else ‘Tokesor’ end) as sc_field_0
from xts_sub_authorisation_statuses
INNER JOIN xts_cards ON xts_cards.ID = xts_sub_authorisation_statuses.CAR_ID_FOR
where CAR_ID_FOR = ///////(if it doesn’t find a value in the database, here it stays empty!!)//////
order by xts_sub_authorisation_statuses.END_DATE DESC, 7, 0) "

How do i make the search app display a “No Record Found” message after the end of an unsuccessful search… instead of this error??

Any idea is greatly appreciated!