This topic is locked

End-of-File? After Record Deleted

6/5/2009 12:06:36 PM
ASPRunnerPro General questions
J
JOHNF777 author

I'm trying to figure out a code to prevent an error...
If I include this code in the AFTER RECORD DELETE and then, delete all the details, I receive and error:

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'where'.
How do I tell my code that rstmp(0) must be zero?
Thanks in advance.
Here's my code:
[codebox]str = "select sum(Total1) AS SubTot from TABLE1 where TableKey=" & dict("tableKey")

Set rstmp = server.CreateObject("ADODB.Recordset")

rstmp.open str,dbConnection
'update master table

dbConnection.Execute "update MASTERTABLE set Totals=" & rstmp(0) & " where TableKey=" & dict("tableKey")
rstmp.close

set rstmp=nothing

[/codebox]

F
funklet 6/6/2009

Hi,
If you do the sum of no records then ADO will return an empty recordset. This is not neccessarily what you are expecting.

Please try the following....
[codebox]totval = 0

str = "select sum(Total1) AS SubTot from TABLE1 where TableKey=" & dict("tableKey")
Set rstmp = server.CreateObject("ADODB.Recordset")

rstmp.open str,dbConnection

if not rstemp.EOF then totval = rstmp(0)

rstmp.close

set rstmp = nothing
'update master table

dbConnection.Execute "update MASTERTABLE set Totals=" & totval & " where TableKey=" & dict("tableKey")[/codebox]

J
JOHNF777 author 6/12/2009

That works! Thanks!