This topic is locked

Before Delete Event

2/18/2007 5:19:05 PM
ASPRunnerPro General questions
K
kconzel author

I have a Time Card table and an authorization table with EmpKey, Month and Campus, actually the field names are:

TblTimeCard: EmpKey, MonthTC, and CampusTC and

QryAuthorizations: EmpKey, MonthAuth, and CampusAuth.

Anything that has been "authorized" by month and campus cannot be edited/added to or deleted from.

I'd like to use an Onload Event but I can't figure that out so I'm trying to set up a "Before Delete Function"

Here's the code. Please, please do you have any idea what I'm doing wrong?

(And also how to set up the Edit Onload Event)
On the TblTimeCard_list.asp page - Events tab
Function BeforeDelete(where)
' Parameters:

' where - string with WHERE clause pointing to record to be deleted.
set rstmp = Server.CreateObject("ADODB.Recordset")

rstmp.Open "select * from QryAuthorizations where EmpKey='" & EmpKey & "' and CampusAuth='" & CampusTC & "' and MonthAuth='" & MonthTC & "'", dbConnection
if rstmp.eof then

BeforeDelete = True

else

BeforeDelete = False

response.write "This campus/month's time has already been authorized and no entries can be changed or deleted"

end if
rstmp.Close : set rstmp = nothing
End Function

Any help would be greatly appreciated.

C
clig 2/18/2007

I have a Time Card table and an authorization table with EmpKey, Month and Campus, actually the field names are:

TblTimeCard: EmpKey, MonthTC, and CampusTC and

QryAuthorizations: EmpKey, MonthAuth, and CampusAuth.

Anything that has been "authorized" by month and campus cannot be edited/added to or deleted from.

I'd like to use an Onload Event but I can't figure that out so I'm trying to set up a "Before Delete Function"

Here's the code. Please, please do you have any idea what I'm doing wrong?

(And also how to set up the Edit Onload Event)
On the TblTimeCard_list.asp page - Events tab
Function BeforeDelete(where)
' Parameters:

' where - string with WHERE clause pointing to record to be deleted.
set rstmp = Server.CreateObject("ADODB.Recordset")

rstmp.Open "select * from QryAuthorizations where EmpKey='" & EmpKey & "' and CampusAuth='" & CampusTC & "' and MonthAuth='" & MonthTC & "'", dbConnection
if rstmp.eof then

BeforeDelete = True

else

BeforeDelete = False

response.write "This campus/month's time has already been authorized and no entries can be changed or deleted"

end if
rstmp.Close : set rstmp = nothing
End Function

Any help would be greatly appreciated.


Do a redirect if your test is true...

J
Jane 2/19/2007

Hi,
you need to pull all values from TblTimeCard table and then compare these values with values from the QryAuthorizations table. Here is a sample:

str = "select from " & strTableName & " where " & where

set rsInfo = Server.CreateObject("ADODB.Recordset")

rsInfo.Open str,dbConnection
set rstmp = Server.CreateObject("ADODB.Recordset")

rstmp.Open "select from QryAuthorizations where EmpKey='" & rsInfo("EmpKey") & "' and CampusAuth='" & rsInfo("CampusTC") & "' and MonthAuth='" & rsInfo("MonthTC") & "'", dbConnection

K
kconzel author 2/19/2007

I tried it using your sample for the Before Delete and it still didn't work.

Here's the code. Any ideas what I'm doing wrong? Do I have the tables backward?

Thanks for any help.
Function BeforeDelete(where)
' Parameters:

' where - string with WHERE clause pointing to record to be deleted.
'** Check if specific record exists ****

str = "select from " & strStaffTimeCard & " where " & where

set rsInfo = Server.CreateObject("ADODB.Recordset")

rsInfo.Open str,dbConnection
set rstmp = Server.CreateObject("ADODB.Recordset")

rstmp.Open "select
from QrySListAuth where EmpKey='" & rsInfo("EmpKey") & "' and CampusAuth='" & rsInfo("Campus") & "' and MonthAuth='" & rsInfo("MonthTC") & "'", dbConnection
if not rsExists.eof then

BeforeDelete = False

response.write "This Time/Effort Entry cannot be deleted. You have already authorized this month and campus."
else

BeforeDelete = True
end if

rsExists.Close : set rsExists = Nothing
' set BeforeDelete to True if you like to proceed with deleting record

' set it to False in other case
End Function

Hi,

you need to pull all values from TblTimeCard table and then compare these values with values from the QryAuthorizations table. Here is a sample:

J
Jane 2/20/2007

Variable strTableName contains table name of the current table. So you don't need to replace it with your actual table name:

...

str = "select * from " & strTableName & " where " & where

set rsInfo = Server.CreateObject("ADODB.Recordset")

rsInfo.Open str,dbConnection

...