Solved

help with if statement

Posted on 2006-10-30
3
130 Views
Last Modified: 2010-04-25
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?

<%
Dim rsdeleteoldcomputers
Dim rsdeleteoldcomputers_numRows

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.Open()

rsdeleteoldcomputers_numRows = 0
%>

<%
If rsdeleteoldcomputers.Recordcount>0 then      <<<<<<AFTER ADDING THIS THE DELETE PROGRAM WONT RUN>
DIM NewsDate
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
comdeleteoldcomputers.Execute()

%>

<%END IF%>

<%
end if
rsdeleteoldcomputers.Close()
Set rsdeleteoldcomputers = Nothing
%>
0
Comment
Question by:elliottbenzle
3 Comments
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 17839999
If you are not doing anyother process other than deleting the records, then no need to open the recordset itself,

<%
Dim comdeleteoldcomputer

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
comdeleteoldcomputers.Execute()

%>

Let me know if this does not work.
0
 
LVL 10

Accepted Solution

by:
aplimedia earned 500 total points
ID: 17848929
Try this instead of > 0. Simply use .EOF (End of file) like this.

rsdeleteoldcomputers.LockType = 1
rsdeleteoldcomputers.Open()

If Not rsdeleteoldcomputers.EOF Then ' <<<<<<<<<<<<<<  If there are records... dont forget to put an end if at the end of your delete sequence.

rsdeleteoldcomputers_numRows = 0
%>

Kind Regards

Aplimedia
0
 
LVL 4

Author Comment

by:elliottbenzle
ID: 17855983
If Not rsdeleteoldcomputers.EOF Then

works great thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dreamweaver Recordset to Array; Loop Array and Perform Calculation 4 573
Simple PHP Upload Script 11 2,709
Site contents shift off page in IE 32 123
Barcode detail gets lost in PDF 3 106
I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now