This topic is locked
[SOLVED]

 Check if specific record exists

4/17/2010 3:03:39 PM
ASPRunnerPro General questions
M
manan author

Hi,
I'm using version ASPRunner Pro 6.2 Built 5242.
At ADD page, Before record added, how do I check for specific records exists? Basically, I want to prevent a user from booking a resource when someone else already added the same booking date. The simple scripting I can think of is:
If Request.Form("date")=rs("date") then

Response.Redirect "book_list.asp"

end if
I actually don't know how to use the default scripting below:
** Check if specific record exists ****

dim rsExists

set dal_table=dal.Table("AnyTable")

set rsExists = dal_table.Query("AnyColumn='AnyValue'","")

if not rsExists.eof then

' if record exists do something
else

' if dont exist do something else
end if

rsExists.Close : set rsExists = Nothing
Please help to provide a sample code to achieve this.
The table is "book" and the column name is "Date".
Thank you.

Sergey Kornilov admin 4/17/2010

You can try something like this:

dim rsExists

set dal_table=dal.Table("book")

set rsExists = dal_table.Query("Date='" & values("Date") & "'","")

if not rsExists.eof then
BeforeAdd=false

message = "This date (" & values("Date") & ") is booked already"
else



BeforeAdd = true
end if

rsExists.Close : set rsExists = Nothing


I guess you also need to add room/property number to equation. i.e.

set rsExists = dal_table.Query("Date='" & values("Date") & "' and RoomNumber=" & values("RoomNumber") ,"")
M
manan author 4/19/2010

Hi Sergey,
Thank you very much for the code sample. I have managed to get it working now. Best Regards.

set rsExists = dal_table.Query("Date='" & values("Date") & "' and BookTitle='" & values("BookTitle") & "'","")