how to prevent entering same value on the same day?

hi guys, i have simple form single record, there is a value that i want to prevent users to add it duplicated on the same day, (type: integer) i have also the date field in the same table fields like {dateofentry} this is to prevent adding a record for the same issue on the same day…but they can add it next day is fine

any hint? using SC8

Mike

onValidate

sc_lookup(rs,“SELECT COUNT(issue) FROM your_table WHERE issue = {issue} AND dateofentry = {dateofentry}”); //depending on your needs, you could also use CURDATE()
if(isset({rs[0][0]}) && {rs[0][0]} > 0)
{
sc_error_message(“Already recorded!”);
sc_error_exit();
}

jsb

YOU ARE THE MAN jsb, like always, a real live saver :smiley:

appreciated dude

its a nice post …

jsb, i tried that it is adding the record normally! maybe i am missing something
my key field which shouldn’t be repeated in the same date is {stno}, and the date field is {dateofentry}, so i put this on validate:

sc_lookup(rs,"SELECT COUNT(stno), FROM daily_act WHERE stno = {stno} AND dateofentry = {dateofentry}");
if(isset({rs[0][0]}) && {rs[0][0]} > 0)
{
sc_error_message("This student is already registered for this day!");
sc_error_exit();
}

then opened this single-record form and added new record that has stno already registered for the same dateofentry, it normally added it, tried again, and could add it many times in the same day

what could be going wrong

Why don’t you just put quotes around your date field. ‘{dateofentry}’ :slight_smile:

Oh, and btw I suggest to put all in the BeforeInsert event.

jsb

Oh, jsb, you didn’t only save a life here, you answered an old question that why date field sometimes jpeople put a quote, even SC internally adds that in the code… i tried to google it long time ago to know more about it but useless, then forgot it loool

anyway, problem was extra coma after the

sc_lookup(rs,"SELECT COUNT(stno), 

when removed the coma, worked as supposed to, i have nothing in the beforeInsert of this form… only the copy of last day data that you gave me earlier it is in OnScriptInt

Appreciated boss

Mike