473,467 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Nested Loop Not working

5 New Member
Hello,
I am attempting to create a nested loop (in Access 2003/VB) that will print a report for a set of user defined months inputed on a form and that will print out for every Client. So the first loop would increment the Client by 1, then the second loop would increment the Month by 1. So the first time around Client A for Month 1, then Client A for month 2 then Client B for Month 1 and so on. Below is what I have already, I can get the nested loop to work and increment the months, but am having a heck of a time incrementing the outer loop (Client). Below is my code so far. Thanks in advance for your help.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_All_SB165_Click()
  2.  
  3.     Dim stDocName As String
  4.     stDocName = "CFDMonthlyReportALLMONTH"
  5.  
  6.     Dim i As Integer
  7.     i = 1
  8.     Dim x As Integer
  9.     x = 0
  10.  
  11.     Do
  12.  
  13.     Do While Forms!ReportChooser!AllMonth.ItemData(x) <> ""
  14.         Forms!ReportChooser!Month = Forms!ReportChooser!AllMonth.ItemData(x)
  15.         Forms!ReportChooser!Client_Box = Forms!ReportChooser!Client_All.ItemData(i)
  16.  
  17.         DoCmd.RunMacro "OpenQNOTE"
  18.  
  19.         DoCmd.OpenReport stDocName, acNormal
  20.  
  21.         DoCmd.RunMacro "CloseQNOTE"
  22.  
  23.         x = x + 1
  24.     Loop
  25.         i = i + 1
  26.     Loop Until Forms!ReportChooser!Client_Box.ItemData(i) = ""
  27.  
  28. End Sub
  29.  
Oct 19 '06 #1
12 3519
Killer42
8,435 Recognized Expert Expert
I wasn't going to reply since this isn't really my area. But since nobody else has put their oar in yet...

One thing which jumped out at me is that this line...
Expand|Select|Wrap|Line Numbers
  1. Forms!ReportChooser!Client_Box = Forms!ReportChooser!Client_All.ItemData(i)
appears to be moving a single element (i) to Client_Box, then this line...
Expand|Select|Wrap|Line Numbers
  1. Loop Until Forms!ReportChooser!Client_Box.ItemData(i) = ""
is testing element (i) from Client_Box. Something just doesn't seem to add up here.

I'll take this pure guess-work one step further - perhaps at the end of the outer loop, you should be testing Client_All.ItemData(i) instead of Client_Box.ItemData(i) ?
Oct 20 '06 #2
upernikaw
5 New Member
Thank you for your response. I completely understand what you are saying...the reason I set it up that way was because I could not figure out how to initialize the increment...I had to assign (i) to Client somehow to increment the data...I'm assuming there has to be a better way but I don't know what that is.

I wasn't going to reply since this isn't really my area. But since nobody else has put their oar in yet...

One thing which jumped out at me is that this line...
Expand|Select|Wrap|Line Numbers
  1. Forms!ReportChooser!Client_Box = Forms!ReportChooser!Client_All.ItemData(i)
appears to be moving a single element (i) to Client_Box, then this line...
Expand|Select|Wrap|Line Numbers
  1. Loop Until Forms!ReportChooser!Client_Box.ItemData(i) = ""
is testing element (i) from Client_Box. Something just doesn't seem to add up here.

I'll take this pure guess-work one step further - perhaps at the end of the outer loop, you should be testing Client_All.ItemData(i) instead of Client_Box.ItemData(i) ?
Oct 20 '06 #3
Killer42
8,435 Recognized Expert Expert
Thank you for your response. I completely understand what you are saying...the reason I set it up that way was because I could not figure out how to initialize the increment...I had to assign (i) to Client somehow to increment the data...I'm assuming there has to be a better way but I don't know what that is.
Sorry I can't be of more help, but did you try the suggestion of testing Client_All.ItemData(i) instead of Client_Box.ItemData(i) in the Loop Until? In other words...
Expand|Select|Wrap|Line Numbers
  1. Loop Until Forms!ReportChooser!Client_All.ItemData(i) = ""
Oct 20 '06 #4
upernikaw
5 New Member
Thank you for trying...I appreciate it...I did try your suggestion but still could not get it to work...I think I'm going to take a day or two without looking at it and then go back to it to get some new perspective. Thanks again for your help.

Sorry I can't be of more help, but did you try the suggestion of testing Client_All.ItemData(i) instead of Client_Box.ItemData(i) in the Loop Until? In other words...
Expand|Select|Wrap|Line Numbers
  1. Loop Until Forms!ReportChooser!Client_All.ItemData(i) = ""
Oct 23 '06 #5
Killer42
8,435 Recognized Expert Expert
Thank you for trying...I appreciate it...I did try your suggestion but still could not get it to work...I think I'm going to take a day or two without looking at it and then go back to it to get some new perspective. Thanks again for your help.
Let us know how it turns out.
Oct 23 '06 #6
albertw
267 Contributor
Let us know how it turns out.
hi

'do while' is no proper statement

better take 2nd loop as while...wend
Oct 24 '06 #7
Killer42
8,435 Recognized Expert Expert
hi
'do while' is no proper statement
better take 2nd loop as while...wend
When you say it's "no proper statement" is this a style thing, or what? It is certainly a valid statement, at least in VB6. Dunno about Access.
Oct 24 '06 #8
albertw
267 Contributor
When you say it's "no proper statement" is this a style thing, or what? It is certainly a valid statement, at least in VB6. Dunno about Access.
hi

do while ... wants to have a value before calculation
in this case the value from the previous loop is used.
if you use 'while' or 'do' only, the new value is taken.
Oct 25 '06 #9
Killer42
8,435 Recognized Expert Expert
do while ... wants to have a value before calculation
in this case the value from the previous loop is used. if you use 'while' or 'do' only, the new value is taken.
Interesting. I wasn't aware of the difference.
Oct 25 '06 #10
upernikaw
5 New Member
Thanks again for the help...I'm still having the same issue though...following is the new code (which I've tried about 10 different variations of):
Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_All_SB165_Click()
  2.  
  3.  
  4.     Dim stDocName As String
  5.     stDocName = "CFDMonthlyReportALLMONTH"
  6.  
  7.     Dim i As Integer
  8.     i = 1
  9.     Dim x As Integer
  10.     x = 0
  11.  
  12.         While Forms!reportchooser!AllMonth.ItemData(x) <> ""
  13.         Forms!reportchooser!Month = Forms!reportchooser!AllMonth.ItemData(x)
  14.  
  15.  
  16.         DoCmd.RunMacro "OpenQNOTE"
  17.  
  18.         DoCmd.OpenReport stDocName, acNormal
  19.  
  20.         DoCmd.RunMacro "CloseQNOTE"
  21.  
  22.         x = x + 1
  23.     Wend
  24.     Forms!reportchooser!Client_Box = Forms!reportchooser!Client_All.ItemData(i)
  25.     i = i + 1
  26.     Loop Until Forms!reportchooser!Client_All.ItemData(i) = ""
  27.  
  28.  
  29. End Sub
  30.  

hi

do while ... wants to have a value before calculation
in this case the value from the previous loop is used.
if you use 'while' or 'do' only, the new value is taken.
Oct 26 '06 #11
upernikaw
5 New Member
Just in case anyone cares...I figured it out...it was actually quite a simple fix...I didn't reset the variable in the inner loop...the code ends up like this:
Expand|Select|Wrap|Line Numbers
  1. Dim stDocName As String
  2.     stDocName = "CFDMonthlyReportALLMONTH"
  3.  
  4.     Dim i As Integer
  5.     i = 0
  6.     x = 1
  7.     Do While Forms!reportchooser!Client_All.ItemData(x) <> ""
  8.         Forms!reportchooser!Client_Run = Forms!reportchooser!Client_All.ItemData(x)
  9.     Do While Forms!reportchooser!AllMonth.ItemData(i) <> ""
  10.         Forms!reportchooser!Month = Forms!reportchooser!AllMonth.ItemData(i)
  11.  
  12.         DoCmd.RunMacro "OpenQNOTE"
  13.  
  14.         DoCmd.OpenReport stDocName, acNormal
  15.  
  16.         DoCmd.RunMacro "CloseQNOTE"
  17.  
  18.         i = i + 1
  19.     Loop
  20.        x = x + 1
  21.        i = 0
  22.     Loop
  23.  
Thanks again for the help...I'm still having the same issue though...following is the new code (which I've tried about 10 different variations of):
Expand|Select|Wrap|Line Numbers
  1. Private Sub Print_All_SB165_Click()
  2.  
  3.  
  4.     Dim stDocName As String
  5.     stDocName = "CFDMonthlyReportALLMONTH"
  6.  
  7.     Dim i As Integer
  8.     i = 1
  9.     Dim x As Integer
  10.     x = 0
  11.  
  12.         While Forms!reportchooser!AllMonth.ItemData(x) <> ""
  13.         Forms!reportchooser!Month = Forms!reportchooser!AllMonth.ItemData(x)
  14.  
  15.  
  16.         DoCmd.RunMacro "OpenQNOTE"
  17.  
  18.         DoCmd.OpenReport stDocName, acNormal
  19.  
  20.         DoCmd.RunMacro "CloseQNOTE"
  21.  
  22.         x = x + 1
  23.     Wend
  24.     Forms!reportchooser!Client_Box = Forms!reportchooser!Client_All.ItemData(i)
  25.     i = i + 1
  26.     Loop Until Forms!reportchooser!Client_All.ItemData(i) = ""
  27.  
  28.  
  29. End Sub
  30.  
Nov 8 '06 #12
Killer42
8,435 Recognized Expert Expert
Just in case anyone cares...I figured it out...it was actually quite a simple fix...I didn't reset the variable in the inner loop...the code ends up like this: ...
I care, and I expect others do. It's good to hear that you found a solution.

Speaking for myself, I just never have the time to chase up all the things I'd like to, so they tend to drop from memory. If you have an outstanding question, feel free to post reminders from time to time so it pops to the top of the list. Don't overdo it though, or you'll invoke the wrath of our dreaded moderators (shudder...) :)
Nov 8 '06 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
46
by: Neptune | last post by:
Hello. I am working my way through Zhang's "Teach yourself C in 24 hrs (2e)" (Sam's series), and for nested loops, he writes (p116) "It's often necessary to create a loop even when you are...
17
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html Why is C# 500% slower than C++ on Nested Loops ??? Will this problem be solved in...
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
2
by: th3dude | last post by:
I am trying to pull out some nested XML using C# and XMLReader. Can't seem to extract the "Items" for each "Product" when i loop through file, i can loop over the "Product" notes just fine but...
4
by: MDR | last post by:
Hello I have three "for" loops, two nested into the outer one and they depend on each other, like this: for (x=1; x<100; x++) { .... for (i=1; i<10; i++) {....} for (j=1; j<10;...
9
by: notahipee | last post by:
Would someone be able to tell me why this isn't working. The nested for loops seem correctly coded to me. I would appreciate any input. #include <iostream.h> #include <math.h> int main () {...
3
by: numlock00 | last post by:
I have a nested 'while' loop that won't repeat, no matter how many times the outer loop repeats. The outer loop reads through an array of elements; the inner loop Ithe 'while' loop) is supposed to...
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.