-
February 23rd, 2011, 10:42 AM
#1
Help error with loop!
For j = lvOrderList.ListItems.Count To 1 Step -1
If rsProducts!Product_ID = lvOrderList.ListItems(j).Text Then
Do
orderQnty = lvOrderList.ListItems(j).ListSubItems(2).Text
rsProducts.Edit
rsProducts!Units_InStock = rsProducts!Units_InStock + orderQnty
rsProducts.Update
Loop Until rsProducts.EOF
End If
Next j
next without for error
the unit in stock should be updated with the data in listview(orderQnty). the productID from listview should first match with ProductID in database.
should then move on to next listview and update...
-
February 23rd, 2011, 10:56 AM
#2
Re: Help error with loop!
You can't subtract 1 from 0, the last time thru your loop.
Either add one to the counter, and subtract in code, or the opposite
-
February 23rd, 2011, 11:02 AM
#3
Re: Help error with loop!
-
February 23rd, 2011, 11:29 AM
#4
Re: Help error with loop!
Notice that you didn't get the FIRST item?
Code:
For j = lvOrderList.ListItems.Count-1 To 0 Step -1
If rsProducts!Product_ID = lvOrderList.ListItems(j).Text Then
Do
orderQnty = lvOrderList.ListItems(j).ListSubItems(2).Text
rsProducts.Edit
rsProducts!Units_InStock = rsProducts!Units_InStock + orderQnty
rsProducts.Update
Loop Until rsProducts.EOF
End If
Next j
Last edited by dglienna; February 24th, 2011 at 01:19 AM.
Reason: Actually that should be count -1 to 0
-
February 23rd, 2011, 02:29 PM
#5
Re: Help error with loop!
Actually that should be count -1 to 0
Code:
Do
orderQnty = lvOrderList.ListItems(j).ListSubItems(2).Text
rsProducts.Edit
rsProducts!Units_InStock = rsProducts!Units_InStock + orderQnty
rsProducts.Update
Loop Until rsProducts.EOF
Why the loop here?
It would appear that this would be endless as you are looping until EOF but not moving the record pointer???
Looks liek you are only needing to update one record and if so no loop is needed. If you want to update more than one record or even if you only want to update a single record and update where query would be a better choice.
Last edited by DataMiser; February 23rd, 2011 at 02:33 PM.
Always use [code][/code] tags when posting code.
-
February 24th, 2011, 01:20 AM
#6
Re: Help error with loop!
Didn't catch that. Correct.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|