help with if statement
Posted on 2006-10-30
I have an include file which deletes records which are more than 14 days old. I was having the problem that if there were no records in the database the page would not display. To stop this I put in another if statment saying that if the recordcount was more than zero then run the delete command. If the database is empty the page works fine. The problem now is that my delete old records program never runs now. If I remove the new if then statement the delete old records program runs fine. Can someone take a look at this and tell me what I'm doing wrong?
Set rsdeleteoldcomputers = Server.CreateObject("ADODB.Recordset")
rsdeleteoldcomputers.ActiveConnection = MM_glowfish_STRING
rsdeleteoldcomputers.Source = "SELECT * FROM sellcomputers ORDER BY currentdate ASC"
rsdeleteoldcomputers.CursorType = 0
rsdeleteoldcomputers.CursorLocation = 2
rsdeleteoldcomputers.LockType = 1
rsdeleteoldcomputers_numRows = 0
If rsdeleteoldcomputers.Recordcount>0 then <<<<<<AFTER ADDING THIS THE DELETE PROGRAM WONT RUN>
NewsDate = rsdeleteoldcomputers.Fields.Item("currentdate").Value
IF NewsDate<DateAdd("d", -14, DATE()) THEN
set comdeleteoldcomputers = Server.CreateObject("ADODB.Command")
comdeleteoldcomputers.ActiveConnection = MM_glowfish_STRING
comdeleteoldcomputers.CommandText = "DELETE sellcomputers.ID, sellcomputers.currentdate, sellcomputers.item, sellcomputers.price, sellcomputers.city, sellcomputers.wantedselling, sellcomputers.name, sellcomputers.address, sellcomputers.description, sellcomputers.telephone, sellcomputers.email FROM sellcomputers WHERE (((sellcomputers.currentdate)<DateAdd('d',-14,Now()))) "
comdeleteoldcomputers.CommandType = 1
comdeleteoldcomputers.CommandTimeout = 0
comdeleteoldcomputers.Prepared = true
Set rsdeleteoldcomputers = Nothing