Looping problem

# Thread: Looping problem

1. Junior Member
Join Date
Dec 1969
Posts
20

## Looping problem

Hi there,<BR>This is driving me mad, so any help would be appreciated. I think i&#039;ve been looking at it too long.<BR><BR>What i&#039;m trying to do:<BR>I have a number of check boxes on a form. These are generated depending upon the entries in another table. The user can make multiple selections, using these check boxes. When the form is submitted, i want to determine the number of check boxes, determine if each check box has been checked or not, and insert the value of any checked boxes (as well as another value) into a table.<BR><BR>Here&#039;s how i&#039;ve tried to do it:<BR><BR>&#039; get the other value required<BR>rs.Open "SELECT MAX(tblStock.Piece_ID)AS topPiece FROM tblStock"<BR><BR>Do While Not rs.Eof<BR>&#039; loop number equal to the number of check boxes<BR>FOR t=1 TO theCounter<BR> &#039; get the next check box whose name includes the value of t<BR> theCategory = TRIM ( Request( "catChoice" & t ))<BR> &#039; if the box has been checked<BR> IF theCategory &#060;&#062; "" THEN<BR> &#039; insert the other value and the check box value<BR> sqlStr = "INSERT INTO tblStockCats " &_<BR> "(intStock_No, intCat_No) " &_<BR> "VALUES (&#039;"&rs("topPiece")&"&#039;, "&theCategory&")"<BR> con.Execute sqlStr<BR> End If<BR>next<BR>loop<BR>rs.Close<BR><BR>What is happening:<BR>It&#039;s running in a continuous loop, repeatedly inserting the correct values into the table. I should note that is does only insert the check boxes that have been checked. I just can&#039;t see why it continues, so any help would be fantastic.<BR><BR>Cheers

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## No MoveNext!!!

Of *COURSE* it is in an infinite loop.<BR><BR>YOu never move away from the first record in the RS recordset.<BR><BR>You need <BR>&nbsp; &nbsp; rs.MoveNext<BR>just before your <BR>&nbsp; &nbsp; Loop<BR>statement.<BR><BR>I&#039;m not sure this is the right way to do what you want, but it will certainly fix the infinite loop problem.<BR><BR>

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## DOH! You don't need MoveNext

Instead, you need to get rid of the silly LOOP completely!<BR><BR>You RS only *HAS* a SINGLE RECORD.<BR><BR>So why would you want to LOOP on a single record???<BR><BR>Replace your <BR>&nbsp; &nbsp; Do While Not rs.Eof<BR>with simply <BR>&nbsp; &nbsp; If Not rs.eof<BR><BR>and then replace<BR>&nbsp; &nbsp; Loop<BR>with simply<BR>&nbsp; &nbsp; End If<BR><BR>Although, really, it would be a major error to get an EOF from that SELECT. So if you wanted to you could even omit the IF and END IF and run "bare".<BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
1,686

## Because its always "not EOF"

Somehow the outer conditional is always satisfied. <BR><BR>If youre always getting an alias, why are you not setting the returned alias to a variable, then closing the recordset, THEN<BR>going through your counter?<BR><BR>dim myValue<BR>rs.Open "SELECT MAX(tblStock.Piece_ID)AS topPiece FROM tblStock"<BR>myValue = rs("topPiece")<BR>rs.Close<BR><BR>for t = 1 to theCounter<BR>&#039; NOW do your insert<BR>next

5. Senior Member
Join Date
Dec 1969
Posts
1,686

## Nice to know

I think like the great Bill Wilkinson this time :)

6. Senior Member
Join Date
Dec 1969
Posts
733

## RE: Looping problem

For Each tCheckBox In Request.form("CheckBox")<BR>SELLECT CASE tCheckBox<BR> CASE "Somevalue"<BR> DO THIS<BR> CASE "some other value"<BR> DO THAT<BR>END SELECT<BR>Next<BR>

7. Senior Member
Join Date
Dec 1969
Posts
1,686

## Emoticons?

First time I&#039;ve seen those before... and if you hover over the one I put in, the ALT text says its "sad"<BR><BR>lol

8. Senior Member
Join Date
Dec 1969
Posts
733

## RE: Looping problem

eh.. "S E L E C T"<BR>sure i can write.. i just can&#039;t spell

9. Senior Member
Join Date
Dec 1969
Posts
96,118

## Sure...look at the HTML for the page

An excerpt thereof:<BR><BR>*************<BR><BR>&#060;FONT SIZE="2" FACE="Tahoma, Verdana, Arial, Helvetica" COLOR="NAVY"&#062;<BR> I think like the great Bill Wilkinson this time &#060;img src="/images/emoticons/emotion-1.gif" border="0" alt="Sad" /&#062;<BR>&#060;/font&#062;<BR><BR>*********<BR><BR>So, of course, the alt is "Sad".<BR><BR>NOW... What I want to know is what did you type to get that?<BR>

10. Senior Member
Join Date
Dec 1969
Posts
413

## Look at the....

Social Forum. ;-)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•