This topic is locked

If...Then...Statments

9/12/2008 11:00:37 PM
ASPRunnerPro General questions
M
mccreelake author

During an AfterAdd() event, I need to execute a specific SQL statement only if a field on the page where the record was added was NOT null. Can you give me an example of how that code my look.
Here is the SQL I need to execute (but only if dict("Orig_Present1") is NOT null):

strSQLInsert2 = "INSERT INTO Events_Clients_NoGrpAff ([Type], Events_EventID, Clients_ClientID) "

strSQLInsert2 = strSQLInsert2 & "values ('Presenter'," & rsTemp(0) & "," & dict("Orig_Present1") & ")"

dbConnection.Execute strSQLInsert2


Thanks!

Sergey Kornilov admin 9/13/2008
if dict("Orig_Present1") not is null

strSQLInsert2 = "INSERT INTO Events_Clients_NoGrpAff ([Type], Events_EventID, Clients_ClientID) "

strSQLInsert2 = strSQLInsert2 & "values ('Presenter'," & rsTemp(0) & "," & dict("Orig_Present1") & ")"

dbConnection.Execute strSQLInsert2

end if
M
mccreelake author 9/15/2008

Thanks. However, now when I go to the page, it is not pulling it up and is giving me an HTTP error. When I cleared my code, the page appeared again. Any help with the code would be appreciated. Also, I have had most of the code in there before and it works...I am really only concerned about the if...then stuff...

str = "select max([EventID]) from Events"

Set rsTemp = server.CreateObject("ADODB.Recordset")
rsTemp.open str, dbConnection
strSQLInsert = "INSERT INTO Groups_Events (Events_EventID, Groups_GroupID, AttnPeriod, Groups_EventCategories_GroupEventCategoryID, NWBPUB, NWBUSR, NWBADM) "

strSQLInsert = strSQLInsert & "values (" & rsTemp(0) & "," & dict("Orig_GroupID") & ",'" & dict("Orig_AttnPeriod") & "'," & dict("Orig_GroupEventCategoryID") & "," & dict("NWBPUB") & "," & dict("NWBUSR") & "," & dict("NWBADM") & ")"

dbConnection.Execute strSQLInsert
if dict("Orig_Present1") not is null then

strSQLInsert2 = "INSERT INTO Events_Clients_NoGrpAff ([Type], Events_EventID, Clients_ClientID) "

strSQLInsert2 = strSQLInsert2 & "values ('Presenter'," & rsTemp(0) & "," & dict("Orig_Present1") & ")"

dbConnection.Execute strSQLInsert2
else if dict("Orig_Present2") not is null then

strSQLInsert3 = "INSERT INTO Events_Clients_NoGrpAff ([Type], Events_EventID, Clients_ClientID) "

strSQLInsert3 = strSQLInsert3 & "values ('Presenter'," & rsTemp(0) & "," & dict("Orig_Present2") & ")"

dbConnection.Execute strSQLInsert3
else if dict("Orig_Present3") not is null then

strSQLInsert4 = "INSERT INTO Events_Clients_NoGrpAff ([Type], Events_EventID, Clients_ClientID) "

strSQLInsert4 = strSQLInsert4 & "values ('Presenter'," & rsTemp(0) & "," & dict("Orig_Present3") & ")"

dbConnection.Execute strSQLInsert4

end if
strSQLUpdate = "UPDATE Events "

strSQLUpdate = strSQLUpdate & "SET Orig_GroupID = Null, Orig_AttnPeriod = Null, Orig_GroupEventCategoryID = Null "

strSQLUpdate = strSQLUpdate & "WHERE EventID = " & rsTemp(0)

dbConnection.Execute strSQLUpdate
rsTemp.Close : set rsTemp = Nothing