473,698 Members | 2,631 Online
Bytes | Software Development & Data Engineering Community
+ 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 3542
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.Item Data(i) instead of Client_Box.Item Data(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.Item Data(i) instead of Client_Box.Item Data(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.Item Data(i) instead of Client_Box.Item Data(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.Item Data(i) instead of Client_Box.Item Data(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

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

Similar topics

5
7296
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; int digit3 = 0; for( ; digit1 < 5 ; digit1++ ) {
46
9915
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 already in a loop." Then he goes on to portray a contrived example that doesn't tell me under what conditions a nested loop might be favoured as a solution? i.e. what are nested loops useful for? What kinds of algorithms are served by nested loops?...
17
3026
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 the future???
77
5210
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. Is this because .NET is inherently slower or does the C# compiler merely produce code that is not as well optimized as the C++ compiler?
2
2427
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 everytime i perform a nested loop over the "Items" list i keep every item on the file listed for each "Product". Is there an easy approach to get the related Items for each Product ID instead of all the Items everytime?
4
1715
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; j++)
9
1881
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 () { int a, b, c, d;
3
4483
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 apply each of these elements while reading an input file. The outer loop is working fine. It will run through every element of the array. The inner loop, however, only runs once. Even though the outer loop finishes inormally, the inner loop does not...
8
7251
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 <Boolean ExpressionThen Exit For Next If Not <Boolean ExpressionThen Exit For
0
8683
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6531
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4624
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.