This topic is locked

Compare data before and after edit

11/16/2006 11:09:52 AM
ASPRunnerPro General questions
N
NigelEtienne author

Upgraded from 4.0 to 4.1.164 and the after edit event only partially works now :
The BeforeEdit function copies the record to tblBackUp (this table is populated) and then creates a message called "message1"

Function BeforeEdit(dict, where)

'

strSQLSave = "INSERT INTO tblBackUp (LeaveID, EmployeeID, MyName, MyEMailAddress, LeaveType, LeaveStart, LeaveEnd, HalfDay, AdditionalInfo, LeaveApproved, LeaveApprovedBy, EMailAddress, AmendedDate, AmendedBy) SELECT LeaveID, EmployeeID, MyName, MyEMailAddress, LeaveType, LeaveStart, LeaveEnd, HalfDay, AdditionalInfo, LeaveApproved, LeaveApprovedBy, EMailAddress, Now(), '" & Session("UserID") & "' FROM " & strTableName & " where " & where

dbConnection.Execute strSQLSave

'

set rsOld = CreateObject("ADODB.Recordset")

message1=""

rsOld.Open "select LeaveID, LeaveStart, LeaveEnd, HalfDay, AdditionalInfo from " & strTableName & " where " & where, dbConnection

if not rsOld.eof then

for i=0 to rsOld.Fields.Count-1

If not IsBinaryField(rsOld.Fields(i)) then _

message1 = message1 & "<tr><td width=135 bgcolor=#C0C0C0 align=right><b>" & rsOld.Fields(i).Name & " : " & "</b></td><td width=97>" & rsOld(rsOld.Fields(i).Name) & "</td></tr>"

next

message1 = "<table border = 1 cellpadding=3 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=235>" & message1 & "</table>"

rsOld.Close

end if

set rsOld = Nothing

session("Message1")= message1

BeforeEdit = True

End Function
The AfterEdit function calls up "message1" and then appends the revised data to the bottom of it so managers can see what has changed.
Sub AfterEdit()
email=GetRequestForm("value_EmailAddress")

message= "<p>" & GetRequestForm("value_MyName") & " has amended the following leave request :" & "</p>" & "<Strong>" & "From" & "</Strong>" & "
" & Session("Message1") & "
" & "<Strong>" & "To" & "</Strong>" & "
" & "<table border = 1 cellpadding=3 cellspacing=0 style=border-collapse: collapse bordercolor=#111111 width=235><tr><td width=135 bgcolor=#83C7C6 align=right><b>Start Date :</b></td><td width=97>" & GetRequestForm("value_LeaveStart") & "</td></tr><tr><td width=135 bgcolor=#83C7C6 align=right><b>End Date :</b></td><td width=97>" & GetRequestForm("value_LeaveEnd") & "</td></tr><tr><td width=135 bgcolor=#83C7C6 align=right><b>HalfDay :</b></td><td width=97>" & GetRequestForm("value_HalfDay") & "</td></tr><tr><td width=135 bgcolor=#83C7C6 align=right><b>AdditionalInfo :</b></td><td width=97>" & GetRequestForm("value_AdditionalInfo")& "</td></tr></table>" & "
<p>Please re-authorise by clicking " & "<a href=http:\\bbcapps1046\GFC_LEAVE\Output\login.asp>here</a> and logging onto the GFC Leave database.<BR>Select <font color=#800080>Main Menu</font> and you will find this request under <font color=#800080>Direct Reports - Outstanding Leave.</font></p>"

'

If GetRequestForm("value_LeaveType") = 1 then

subject="Amended ANNUAL Leave Request from " & GetRequestForm("value_MyName")

ElseIf GetRequestForm("value_LeaveType") = 2 then

subject="Amended LONG SERVICE Leave Request from " & GetRequestForm("value_MyName")

ElseIf GetRequestForm("value_LeaveType") = 3 then

subject="Amended ADDITIONAL Leave Request from " & GetRequestForm("value_MyName")

ElseIf GetRequestForm("value_LeaveType") = 4 then

subject="Amended COMPASSIONATE Leave Request from " & GetRequestForm("value_MyName")

ElseIf GetRequestForm("value_LeaveType") = 5 then

subject="Amended MATERNITY Leave Request from " & GetRequestForm("value_MyName")

ElseIf GetRequestForm("value_LeaveType") = 6 then

subject="Amended TRAINING Leave Request from " & GetRequestForm("value_MyName")

ElseIf GetRequestForm("value_LeaveType") = 7 then

subject="Amended STUDY Leave Request from " & GetRequestForm("value_MyName")

ElseIf GetRequestForm("value_LeaveType") = 9 then

subject="Amended BOUGHT/(SOLD) Leave Request from " & GetRequestForm("value_MyName")

ElseIf GetRequestForm("value_LeaveType") = 10 then

subject="Amended HOME WORKING Request from " & GetRequestForm("value_MyName")

else

subject="Amended Leave Request from " & GetRequestForm("value_MyName")

end if

sendmail email, subject, message

Response.Redirect "tblLeaveRequestslist.asp?action=backtolist"

End If

End Sub
This
did work prior to the upgrade - I have amended the code to add "value?" to each line but cannot get the "message1" to show on the email.

Sergey Kornilov admin 11/16/2006

Nigel,
the code itself looks good. I can recommend the following:

  1. Make sure Session("Message1") is populated.
    Use Response.Write Session("Message 1") in BeforeEdit event
  2. Move all code from AfterEdit Event to BeforeEdit (except for redirect).

    Instead of GetRequestForm use dict("FieldName") which is a recommended method to access field values.

    This way you know that this code works in future versions.

N
NigelEtienne author 11/17/2006

Nigel,

the code itself looks good. I can recommend the following:

  1. Make sure Session("Message1") is populated.
    Use Response.Write Session("Message 1") in BeforeEdit event
  2. Move all code from AfterEdit Event to BeforeEdit (except for redirect).

    Instead of GetRequestForm use dict("FieldName") which is a recommended method to access field values.

    This way you know that this code works in future versions.


Many thanks - now working.