This topic is locked
[SOLVED]

 Validation

10/29/2012 4:21:30 PM
ASPRunnerPro General questions
H
hsan author

I know this sounds trivial, but I cannot get it to work. In table "Checkins" I have two date fields : "datein" and "dateout". How can I validate on Add Page event (preferably OnLoad) that none of previous records have empty "dateout" fileds before I could add new record? New record should be allowed empty "dateout". Help greatly appreciated, as usual.
Thanks,

Nash

T
Tim 10/30/2012

How about this in the Before Add section:



sql = "select * from checkins where isnull(dateout,'') <> ''"

Set objRS = Server.CreateObject("ADODB.Recordset")

objRS.Open sql, dbConnection

if not objRS.eof then

flush_output

response.write "Close the other checkin first"

BeforeAdd=false

else

BeforeAdd=True

end if


If you want it before the page loads maybe this would work in the Before Display section:



sql = "select * from checkins where dateout is null"

Set objRS = Server.CreateObject("ADODB.Recordset")

objRS.Open sql, dbConnection

if not objRS.eof then

response.redirect "somepage.asp"

end if


That would just send them to another page, though, with no explination of why.
I haven't tested either of these, but it's something to try.

Good luck.

Tim

H
hsan author 10/30/2012

Thanks a lot Tim, I will try both options & let you know. I tried similar code for "before add", but the problem was that it was preventing adding new record with empty "dateout" even if all previous records were populated.

H
hsan author 11/6/2012

I am expanding on this - since "checkins" is a child table, I wanted to make sure the subject record has correct key value, but also to prevent adding new record if "DateOut" is empty :
dim rsExists

set dal_table=dal.Table("checkins")

set rsExists = dal_table.Query("JobNo='" & Session(strTableName & "_masterkey1") & "' and DateOut='" & values("NULL") & "'","")

if not rsExists.eof then

BeforeAdd=false
I cannot find a proper syntax for "DateOut" being empty! Above does not work. Help please!
Regards,

Nash

admin 11/8/2012

Nash,
would it help if you set DateOut field as required in ASPRunnerPro? This way it never going to be NULL.

H
hsan author 11/8/2012



Nash,
would it help if you set DateOut field as required in ASPRunnerPro? This way it never going to be NULL.


Not really because one "dateuot" must be always open (empty) during the process. The holder of empty "dateout" is the process owner.

admin 11/8/2012

Okay, it makes sense.
You can try the following:

DateOut is NULL


The syntax might be different for your database. Google "check if field is null <your database type here>" for more info.

H
hsan author 11/8/2012

Sergey,
Tim's query (thanks Tim!) slightly modifed is working:
sql = "select * from checkins where(JobNo ='" & Session(strTableName & "_masterkey1")& "') and DateOut is null"
The issue is I could not use it in dal - could not make proper syntax to make "DateOut is null" work.
Anyhow, this is solved. Thanks!!