Previous Thread

8/10/2006 10:17:02 PM    Looping through Macro
I have a loop within a loop in a macro. It is working, however this causes an 
 
error if it loops more than the allowed 20 times.  I am not a coder, but may 
 
have to do this with code.  Can someone help with code?  Or maybe I am just 
 
doing this all wrong.  Need to run report for each monthly period for each of 
 
5 or more waste types. 
 
Parameter inputs on a form: 
 
FromDate = 1/1/06 
 
ToDate     = 3/30/07 
 
Set ProcessedDates for 1st month  (1/1/06 - 1/31/06) 
 
Count records in WasteType and set RecCount 
 
Set ProcessedCount = 1 
 
Read first record in WasteType Table and set Waste Type 
 
First loop: 
 
Process and append data to table  (for later export to Excel) 
 
Run macro (Second Loop) to select next WasteType 
 
If we have run all Waste types for the month, ( RecCount =ProcessedCount) 
 
Increment the month, start and end dates 
 
Set Waste Type to first record 
 
And go to top of First Loop 
 
Else go to next statement 
 
If we have processed all requested months (ToDate = ProcessedDate) 
 
Stop Macro 
 
Second Loop: 
 
If not at EOF (ProcessedCount = RecCount) 
 
Read next record in Waste Type Table to get next WasteType 
 
Increment ProcessedCount by 1 
 
Go to First Loop 
 
Else 
 
Go to First Record in WasteType Table 
 
Set ProcessCount = 1 
 
Go to First Loop 
 
Hope this makes sense.  Thanks for any help.



8/11/2006 8:20:47 PM    Re: Looping through Macro
GeorgieGirl, 
 
Can you give the details of the actions you have in your macro?  And can 
 
you explain what you mean by "the allowed 20 times"? 
 
-- 
 
Steve Schapel, Microsoft Access MVP 
 
GeorgieGirl wrote:

8/12/2006 9:11:20 AM    Re: Looping through Macro
GeorgieGirl, 
 
Thanks.  Well, your explanation did not help me to answer your 
 
question... for that I need the details of your macro, for example the 
 
exact name of the macro, the exact Actions of the macro, and Conditions 
 
in the macro, and the Arguments of each macro action. 
 
It is interesting about the "20 times" message.  I have never seen this 
 
before.  I guess it is very unusual to have a macro "call itelf". 
 
Normally a RunMacro action would be calling a separate macro, in which 
 
case there is definitley no limit to the number of recursions. 
 
But anyway, your explanation did alert me to the fact that you are 
 
probaqbly doing this way more complicated that it needs to be.  If you 
 
like, we can divert off to an exploration of other options.  On the 
 
basis of what you have said so far, it seems to me that you could make a 
 
single query to return the data you want.  Can you let me know the 
 
details of the table structure?  ("Details" means names of tables, names 
 
of fields, data types, relationships between tables, and meaning of data 
 
if it is not obvious from the field name). 
 
-- 
 
Steve Schapel, Microsoft Access MVP 
 
GeorgieGirl wrote:

8/13/2006 7:37:39 AM    Re: Looping through Macro
GeorgieGirl, 
 
Thanks for the clarification.  It helps a lot. 
 
I am puzzled by the requirement "Build an Access table ..."  Are you 
 
aware that you can export to an Excel workbook (I assume you would be 
 
using a TransferSpreadsheet action in your macro?), directly from a 
 
query.  I.e. you don't need a table.  I guess that is what I was 
 
thinking all along.  Make a query to return the data you want, and then 
 
just export it.  You mentioned the "Facilities without WasteHistory for 
 
each WasteType" query.  It sounds like you have already built this query 
 
- is this correct?  So, doesn't this query give you the data that you 
 
need?  Why not just export this query, and that's that? 
 
-- 
 
Steve Schapel, Microsoft Access MVP 
 
GeorgieGirl wrote:

8/13/2006 11:25:14 AM    Re: Looping through Macro
GeorgieGirl, 
 
Ok, thanks again for the further clarification.  So, your existing query 
 
only does one month and one waste type.  Can you give details of what 
 
you have so far?  It should be pretty easy to modify it to cover all 
 
your required data.  But at least now I start to understand why you were 
 
thinking to use looping code to achieve your purpose :-) . 
 
-- 
 
Steve Schapel, Microsoft Access MVP 
 
GeorgieGirl wrote: