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. -
Private Sub Print_All_SB165_Click()
-
-
Dim stDocName As String
-
stDocName = "CFDMonthlyReportALLMONTH"
-
-
Dim i As Integer
-
i = 1
-
Dim x As Integer
-
x = 0
-
-
Do
-
-
Do While Forms!ReportChooser!AllMonth.ItemData(x) <> ""
-
Forms!ReportChooser!Month = Forms!ReportChooser!AllMonth.ItemData(x)
-
Forms!ReportChooser!Client_Box = Forms!ReportChooser!Client_All.ItemData(i)
-
-
DoCmd.RunMacro "OpenQNOTE"
-
-
DoCmd.OpenReport stDocName, acNormal
-
-
DoCmd.RunMacro "CloseQNOTE"
-
-
x = x + 1
-
Loop
-
i = i + 1
-
Loop Until Forms!ReportChooser!Client_Box.ItemData(i) = ""
-
-
End Sub
-
12 3519
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... - Forms!ReportChooser!Client_Box = Forms!ReportChooser!Client_All.ItemData(i)
appears to be moving a single element (i) to Client_Box, then this line... - 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) ?
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... - Forms!ReportChooser!Client_Box = Forms!ReportChooser!Client_All.ItemData(i)
appears to be moving a single element (i) to Client_Box, then this line... - 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) ?
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... - Loop Until Forms!ReportChooser!Client_All.ItemData(i) = ""
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... - Loop Until Forms!ReportChooser!Client_All.ItemData(i) = ""
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.
Let us know how it turns out.
hi
'do while' is no proper statement
better take 2nd loop as while...wend
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.
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.
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.
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): -
Private Sub Print_All_SB165_Click()
-
-
-
Dim stDocName As String
-
stDocName = "CFDMonthlyReportALLMONTH"
-
-
Dim i As Integer
-
i = 1
-
Dim x As Integer
-
x = 0
-
-
While Forms!reportchooser!AllMonth.ItemData(x) <> ""
-
Forms!reportchooser!Month = Forms!reportchooser!AllMonth.ItemData(x)
-
-
-
DoCmd.RunMacro "OpenQNOTE"
-
-
DoCmd.OpenReport stDocName, acNormal
-
-
DoCmd.RunMacro "CloseQNOTE"
-
-
x = x + 1
-
Wend
-
Forms!reportchooser!Client_Box = Forms!reportchooser!Client_All.ItemData(i)
-
i = i + 1
-
Loop Until Forms!reportchooser!Client_All.ItemData(i) = ""
-
-
-
End Sub
-
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.
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: -
Dim stDocName As String
-
stDocName = "CFDMonthlyReportALLMONTH"
-
-
Dim i As Integer
-
i = 0
-
x = 1
-
Do While Forms!reportchooser!Client_All.ItemData(x) <> ""
-
Forms!reportchooser!Client_Run = Forms!reportchooser!Client_All.ItemData(x)
-
Do While Forms!reportchooser!AllMonth.ItemData(i) <> ""
-
Forms!reportchooser!Month = Forms!reportchooser!AllMonth.ItemData(i)
-
-
DoCmd.RunMacro "OpenQNOTE"
-
-
DoCmd.OpenReport stDocName, acNormal
-
-
DoCmd.RunMacro "CloseQNOTE"
-
-
i = i + 1
-
Loop
-
x = x + 1
-
i = 0
-
Loop
-
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): -
Private Sub Print_All_SB165_Click()
-
-
-
Dim stDocName As String
-
stDocName = "CFDMonthlyReportALLMONTH"
-
-
Dim i As Integer
-
i = 1
-
Dim x As Integer
-
x = 0
-
-
While Forms!reportchooser!AllMonth.ItemData(x) <> ""
-
Forms!reportchooser!Month = Forms!reportchooser!AllMonth.ItemData(x)
-
-
-
DoCmd.RunMacro "OpenQNOTE"
-
-
DoCmd.OpenReport stDocName, acNormal
-
-
DoCmd.RunMacro "CloseQNOTE"
-
-
x = x + 1
-
Wend
-
Forms!reportchooser!Client_Box = Forms!reportchooser!Client_All.ItemData(i)
-
i = i + 1
-
Loop Until Forms!reportchooser!Client_All.ItemData(i) = ""
-
-
-
End Sub
-
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...) :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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;...
|
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...
|
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...
|
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....
|
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...
|
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;...
|
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 ()
{...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |