How to display an error message?

How I set condition that show an error message if I select “Start Date” less than the previous “End Date” in Sales Price (ID: 7002) Table.The Start Date must be greater than the previous End Date.

For this I try to write a code in the on Validate trigger of Start Date in sales price table (ID: 7002).But It’s not working properly.

My following code is:

SalesPrice.SETRANGE(SalesPrice.“Item No.”,“Item No.”); //“Here I assign SalesPrice as a Record variable”
SalesPrice.SETRANGE(SalesPrice.“Sales Code”,“Sales Code”);
IF SalesPrice.FINDLAST THEN BEGIN
IF SalesPrice.“Starting Date”<“Ending Date” THEN
ERROR(‘StartDate Must Be Greater Then Previous EndDate’);
END;

Kindly check and give a sugg.

Thank you.

You need to first find the END Date of previous record in variable and then check it in condition

once see whether the data is coming on variables or not ,condition is correct . check it once