Solved

help with if statement

Posted on 2006-10-30
3
133 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hide/ show a recordset row item 6 460
Dreamweaver CC:  ASP VBScript not displayed in "Page Type" 7 2,841
can i use dw to modify this site 1 325
JQuery form validation for bootstrap 1 198
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

733 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