You could check the value of the box such as and this is not in PHP or Perl but you should be able to figure it out.
If Box5.Value = nil then
and then make a statment to deal with it by only using a 4 field query. Basicly what your doing is checking the value of the fields using whatever the scripting language is before performing the SQl query.
Assuming the field names of the table are field1 thru field5.
String whereClause = empty string;
if (box1.value is not empty) then
if (whereClause is not empty) then
whereClause = whereClause + " AND ";
end if;
whereClause = whereClause + " field1 = " + box1.value ;
end if;
Use the above IF condition for all the 5 boxes/fields. I.e. for box2/field2 the IF condition would be -
if (box2.value is not empty) then
if (whereClause is not empty) then
whereClause = whereClause + " AND ";
end if;
whereClause = whereClause + " field2 = " + box2.value ;
end if;
Finally, the variable "whereClause" will have the value which you can use in the WHERE condition of your SQL.