never exit while / wend loop

Hi All.

I have a quick question.

In a database I have, I want to delete all entries with a DATACUSTOMER name of Idle.

Here is the code:

[code]Dim siteRS as RecordSet
'dim z as Integer
dim wipesql as String

sql = "SELECT * FROM ACTIVITY Where DATACUSTOMER = ‘Idle’ "
wipesql = "DELETE FROM ACTIVITY Where DATACUSTOMER = ‘Idle’ "

siteRS = DB.SqlSelect(sql)

if DBError then Return

'Get Each entry in the database and put it in the listbox

if siteRS <> NIL Then
while not siteRS.EOF
DB.sqlexecute(wipesql)
wend
else
MessageBox(“Nothing to Delete”)
siteRS.Close

end if

MessageBox (“Done”)[/code]

When I step through the method, I never exit. However if I close the program and then reopen it, the Idle fields are removed. The project never gets out of the loop.

Any ideas?

Regards

Yup. You don’t need the while-wend Loop at all.

if siteRS <> NIL and (not siteRS.EOF) Then DB.sqlexecute(wipesql) else MessageBox("Nothing to Delete") siteRS.Close end if
Since you are not interating through siteRS, it will never be at EOF - that’s why you get the endless-loop :wink:

I found my error… boy I need to get out of the horseradish… I forgot the

siteRs.Movenext.

Sorry for wasting your time, folks.

Regards

Thanks for the reply Jurg… I will try and implement it in the revised version.

Regards

Again… you don’t need that.
You do not want to execute the delete statement multiple times, do you?

Hi Jurg.

I want to remove all instances of a customer name Idle… so Yes.
But if your code works better, hey I’ll use that.

Regards

I think that Jurg’s point is that the sql statement wipesql = "DELETE FROM ACTIVITY Where DATACUSTOMER = 'Idle' " does the work in one step. Iterating through the "SELECT * FROM ACTIVITY Where DATACUSTOMER = 'Idle' " recordset just does it repeatedly, where once was sufficient.

In clear, if you have 10 records where DATACUSTOMER = ‘Idle’, the delete command will wipe them all in one step. Iterating through the select recordset will issue the command 9 times too many. His code is definitely more optimized.

You also don’t need to select them first.

[quote=467018:@Michael Cebasek]Hi Jurg.

I want to remove all instances of a customer name Idle… so Yes.
But if your code works better, hey I’ll use that.

Regards[/quote]

https://www.w3schools.com/sql/sql_delete.asp