# never exit while / wend loop

**URL:** <https://forum.xojo.com/t/never-exit-while-wend-loop/51546>\
**Category:** General\
**Created:** [December 11, 2019, 1:42pm UTC](https://forum.xojo.com/t/never-exit-while-wend-loop/51546 "2019-12-11T13:42:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Cebasek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@Michael\_Cebasek](https://forum.xojo.com/u/Michael_Cebasek)\
**Post date:** [December 11, 2019, 1:42pm UTC](https://forum.xojo.com/t/never-exit-while-wend-loop/51546/1 "2019-12-11T13:42:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jürg\_Otter](https://forum.xojo.com/user_avatar/forum.xojo.com/j%C3%BCrg_otter/32/584_2.png) [@Jürg\_Otter](https://forum.xojo.com/u/J%C3%BCrg_Otter)\
**Post date:** [December 11, 2019, 1:45pm UTC](https://forum.xojo.com/t/never-exit-while-wend-loop/51546/2 "2019-12-11T13:45:32Z")

</div>

> [@467013:@Michael Cebasek](#):
>
> Any ideas?

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 😉

---

<div class="post-metadata">

**Author:** ![Michael\_Cebasek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@Michael\_Cebasek](https://forum.xojo.com/u/Michael_Cebasek)\
**Post date:** [December 11, 2019, 1:46pm UTC](https://forum.xojo.com/t/never-exit-while-wend-loop/51546/3 "2019-12-11T13:46:42Z")

</div>

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

```auto
siteRs.Movenext.
```

Sorry for wasting your time, folks.

Regards

---

<div class="post-metadata">

**Author:** ![Michael\_Cebasek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@Michael\_Cebasek](https://forum.xojo.com/u/Michael_Cebasek)\
**Post date:** [December 11, 2019, 1:47pm UTC](https://forum.xojo.com/t/never-exit-while-wend-loop/51546/4 "2019-12-11T13:47:43Z")

</div>

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

Regards

---

<div class="post-metadata">

**Author:** ![Jürg\_Otter](https://forum.xojo.com/user_avatar/forum.xojo.com/j%C3%BCrg_otter/32/584_2.png) [@Jürg\_Otter](https://forum.xojo.com/u/J%C3%BCrg_Otter)\
**Post date:** [December 11, 2019, 1:48pm UTC](https://forum.xojo.com/t/never-exit-while-wend-loop/51546/5 "2019-12-11T13:48:18Z")

</div>

> [@467015:@Michael Cebasek](#):
>
> I forgot the siteRs.Movenext.

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

---

<div class="post-metadata">

**Author:** ![Michael\_Cebasek](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/3d9bf3/32.png) [@Michael\_Cebasek](https://forum.xojo.com/u/Michael_Cebasek)\
**Post date:** [December 11, 2019, 2:04pm UTC](https://forum.xojo.com/t/never-exit-while-wend-loop/51546/6 "2019-12-11T14:04:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Louis\_D](https://forum.xojo.com/letter_avatar_proxy/v4/letter/l/cab0a1/32.png) [@Louis\_D](https://forum.xojo.com/u/Louis_D)\
**Post date:** [December 11, 2019, 2:33pm UTC](https://forum.xojo.com/t/never-exit-while-wend-loop/51546/7 "2019-12-11T14:33:23Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kem\_Tekinay](https://forum.xojo.com/user_avatar/forum.xojo.com/kem_tekinay/32/154_2.png) [@Kem\_Tekinay](https://forum.xojo.com/u/Kem_Tekinay)\
**Post date:** [December 11, 2019, 2:45pm UTC](https://forum.xojo.com/t/never-exit-while-wend-loop/51546/8 "2019-12-11T14:45:44Z")

</div>

You also don’t need to select them first.

---

<div class="post-metadata">

**Author:** ![Ivan\_Tellez](https://forum.xojo.com/letter_avatar_proxy/v4/letter/i/a9a28c/32.png) [@Ivan\_Tellez](https://forum.xojo.com/u/Ivan_Tellez)\
**Post date:** [December 11, 2019, 2:56pm UTC](https://forum.xojo.com/t/never-exit-while-wend-loop/51546/9 "2019-12-11T14:56:09Z")

</div>

[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](https://www.w3schools.com/sql/sql_delete.asp)

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 4:12pm UTC](https://forum.xojo.com/t/never-exit-while-wend-loop/51546/10 "2021-04-29T16:12:48Z")

</div>


