I have a database with 1 update query for each department i.e. department 1 - 160.
The update query updates a table (simply storing the deptno) that is then used to make another table and print a report.
What I want to do is use code to loop through that process, ie for each record on department table run the make table query then print the report and then move onto the next record.
The departments is broken into different reporting funcions e.g. balance sheet, profit and loss, Operations, etc etc.
I know conceptually what I want but putting it practice is a little tougher as my programming skills are limited (but getting better)
I am thinking something like
Do:
make table query
print report
until:
deptno = top where [Repfunct] = 'balancesheet'
So I am wanting to make the table run the report until I reach the last deptno for that reporting function.
I started to try to write some code but I really and quite confused as to how I go about it.
my make table query is fairly complicated (and will change depending on the reporting function) so running the query maybe easier than adding the code??:
SELECT DISTINCTROW First(GLPlans.[PRFT CNTRE]) AS [FirstOfPRFT CNTRE], Last(GLPlans.[PRFT CNTRE]) AS [LastOfPRFT CNTRE], First(Department.DEPARTMENT) AS FirstOfDEPARTMENT, Last(Department.DEPARTMENT) AS LastOfDEPARTMENT, First(Department.MANAGER) AS FirstOfMANAGER, GLPlans.[ACC NO], GLAccounts.[ACC DESC], GLAccounts.[ACC TYPE], Sum([GLPLANS]![JUN5]) AS MthAct, Sum([GLPLANS]![JUN2]) AS MthBud, ([MthBud]-[MthAct]) AS VAR1, +IIf([MthBud]=0,0,(([MthAct]/[MthBud])-1)) AS [%1], Sum([GLPLANS]![JUN4]) AS MthLF, ([MthLF]-[MthAct]) AS VAR2, +IIf([MthAct]=0,0,(([MthLF]/[MthAct])-1)) AS [%2], Sum([GLPLANS]![JUL5]+[GLPLANS]![AUG5]+[GLPLANS]![SEP5]+[GLPLANS]![OCT5]+[GLPLANS]![NOV5]+[GLPLANS]![DEC5]+[GLPLANS]![JAN5]+[GLPLANS]![FEB5]+[GLPLANS]![MAR5]+[GLPLANS]![APR5]+[GLPLANS]![MAY5]+[GLPLANS]![JUN5]) AS ACTYTD, Sum([GLPlans]![JUL2]+[GLPlans]![AUG2]+[GLPlans]![SEP2]+[GLPlans]![OCT2]+[GLPlans]![NOV2]+[GLPlans]![DEC2]+[GLPlans]![JAN2]+[GLPlans]![FEB2]+[GLPlans]![MAR2]+[GLPlans]![APR2]+[GLPlans]![MAY2]+[GLPlans]![JUN2]) AS BUDYTD, ([BUDYTD]-[ACTYTD]) AS VAR3, +IIf([ACTYTD]=0,0,(([BUDYTD]/[ACTYTD])-1)) AS [%3], Sum([GLPlans]![JUL4]+[GLPlans]![AUG4]+[GLPlans]![SEP4]+[GLPlans]![OCT4]+[GLPlans]![NOV4]+[GLPlans]![DEC4]+[GLPlans]![JAN4]+[GLPlans]![FEB4]+[GLPlans]![MAR4]+[GLPlans]![APR4]+[GLPlans]![MAY4]+[GLPlans]![JUN4]) AS REESTYTD, [REESTYTD]-[ACTYTD] AS VAR4, +IIf([ACTYTD]=0,0,(([REESTYTD]/[ACTYTD])-1)) AS [%4], Sum([GLPlans]![JUL2]+[GLPlans]![AUG2]+[GLPlans]![SEP2]+[GLPlans]![OCT2]+[GLPlans]![NOV2]+[GLPlans]![DEC2]+[GLPlans]![JAN2]+[GLPlans]![FEB2]+[GLPlans]![MAR2]+[GLPlans]![APR2]+[GLPlans]![MAY2]+[GLPlans]![JUN2]) AS BUD, Sum([GLPlans]![JUL4]+[GLPlans]![AUG4]+[GLPlans]![SEP4]+[GLPlans]![OCT4]+[GLPlans]![NOV4]+[GLPlans]![DEC4]+[GLPlans]![JAN4]+[GLPlans]![FEB4]+[GLPlans]![MAR4]+[GLPlans]![APR4]+[GLPlans]![MAY4]+[GLPlans]![JUN4]) AS REEST INTO PCentre
FROM GLAccounts RIGHT JOIN ((Department LEFT JOIN cc ON Department.[PRFT CNTRE] = cc.[Cost Centre]) RIGHT JOIN GLPlans ON Department.[PRFT CNTRE] = GLPlans.[PRFT CNTRE]) ON GLAccounts.[ACC NO] = GLPlans.[ACC NO]
WHERE (((Department.[PRFT CNTRE])=[CC]![Cost Centre]))
GROUP BY GLPlans.[ACC NO], GLAccounts.[ACC DESC], GLAccounts.[ACC TYPE]
HAVING (((Sum([GLPLANS]![JUN5]))<>0)) OR (((Sum([GLPLANS]![JUN2]))<>0)) OR (((Sum([GLPLANS]![JUN4]))<>0)) OR (((Sum([GLPLANS]![JUL5]+[GLPLANS]![AUG5]+[GLPLANS]![SEP5]+[GLPLANS]![OCT5]+[GLPLANS]![NOV5]+[GLPLANS]![DEC5]+[GLPLANS]![JAN5]+[GLPLANS]![FEB5]+[GLPLANS]![MAR5]+[GLPLANS]![APR5]+[GLPLANS]![MAY5]+[GLPLANS]![JUN5]))<>0)) OR (((Sum([GLPlans]![JUL2]+[GLPlans]![AUG2]+[GLPlans]![SEP2]+[GLPlans]![OCT2]+[GLPlans]![NOV2]+[GLPlans]![DEC2]+[GLPlans]![JAN2]+[GLPlans]![FEB2]+[GLPlans]![MAR2]+[GLPlans]![APR2]+[GLPlans]![MAY2]+[GLPlans]![JUN2]))<>0)) OR (((Sum([GLPlans]![JUL4]+[GLPlans]![AUG4]+[GLPlans]![SEP4]+[GLPlans]![OCT4]+[GLPlans]![NOV4]+[GLPlans]![DEC4]+[GLPlans]![JAN4]+[GLPlans]![FEB4]+[GLPlans]![MAR4]+[GLPlans]![APR4]+[GLPlans]![MAY4]+[GLPlans]![JUN4]))<>0)) OR (((Sum([GLPlans]![JUL2]+[GLPlans]![AUG2]+[GLPlans]![SEP2]+[GLPlans]![OCT2]+[GLPlans]![NOV2]+[GLPlans]![DEC2]+[GLPlans]![JAN2]+[GLPlans]![FEB2]+[GLPlans]![MAR2]+[GLPlans]![APR2]+[GLPlans]![MAY2]+[GLPlans]![JUN2]))<>0)) OR (((Sum([GLPlans]![JUL4]+[GLPlans]![AUG4]+[GLPlans]![SEP4]+[GLPlans]![OCT4]+[GLPlans]![NOV4]+[GLPlans]![DEC4]+[GLPlans]![JAN4]+[GLPlans]![FEB4]+[GLPlans]![MAR4]+[GLPlans]![APR4]+[GLPlans]![MAY4]+[GLPlans]![JUN4]))<>0))
ORDER BY First(GLPlans.[PRFT CNTRE]), Last(GLPlans.[PRFT CNTRE]), GLPlans.[ACC NO];
Any help much appreciated.
The update query updates a table (simply storing the deptno) that is then used to make another table and print a report.
What I want to do is use code to loop through that process, ie for each record on department table run the make table query then print the report and then move onto the next record.
The departments is broken into different reporting funcions e.g. balance sheet, profit and loss, Operations, etc etc.
I know conceptually what I want but putting it practice is a little tougher as my programming skills are limited (but getting better)
I am thinking something like
Do:
make table query
print report
until:
deptno = top where [Repfunct] = 'balancesheet'
So I am wanting to make the table run the report until I reach the last deptno for that reporting function.
I started to try to write some code but I really and quite confused as to how I go about it.
my make table query is fairly complicated (and will change depending on the reporting function) so running the query maybe easier than adding the code??:
SELECT DISTINCTROW First(GLPlans.[PRFT CNTRE]) AS [FirstOfPRFT CNTRE], Last(GLPlans.[PRFT CNTRE]) AS [LastOfPRFT CNTRE], First(Department.DEPARTMENT) AS FirstOfDEPARTMENT, Last(Department.DEPARTMENT) AS LastOfDEPARTMENT, First(Department.MANAGER) AS FirstOfMANAGER, GLPlans.[ACC NO], GLAccounts.[ACC DESC], GLAccounts.[ACC TYPE], Sum([GLPLANS]![JUN5]) AS MthAct, Sum([GLPLANS]![JUN2]) AS MthBud, ([MthBud]-[MthAct]) AS VAR1, +IIf([MthBud]=0,0,(([MthAct]/[MthBud])-1)) AS [%1], Sum([GLPLANS]![JUN4]) AS MthLF, ([MthLF]-[MthAct]) AS VAR2, +IIf([MthAct]=0,0,(([MthLF]/[MthAct])-1)) AS [%2], Sum([GLPLANS]![JUL5]+[GLPLANS]![AUG5]+[GLPLANS]![SEP5]+[GLPLANS]![OCT5]+[GLPLANS]![NOV5]+[GLPLANS]![DEC5]+[GLPLANS]![JAN5]+[GLPLANS]![FEB5]+[GLPLANS]![MAR5]+[GLPLANS]![APR5]+[GLPLANS]![MAY5]+[GLPLANS]![JUN5]) AS ACTYTD, Sum([GLPlans]![JUL2]+[GLPlans]![AUG2]+[GLPlans]![SEP2]+[GLPlans]![OCT2]+[GLPlans]![NOV2]+[GLPlans]![DEC2]+[GLPlans]![JAN2]+[GLPlans]![FEB2]+[GLPlans]![MAR2]+[GLPlans]![APR2]+[GLPlans]![MAY2]+[GLPlans]![JUN2]) AS BUDYTD, ([BUDYTD]-[ACTYTD]) AS VAR3, +IIf([ACTYTD]=0,0,(([BUDYTD]/[ACTYTD])-1)) AS [%3], Sum([GLPlans]![JUL4]+[GLPlans]![AUG4]+[GLPlans]![SEP4]+[GLPlans]![OCT4]+[GLPlans]![NOV4]+[GLPlans]![DEC4]+[GLPlans]![JAN4]+[GLPlans]![FEB4]+[GLPlans]![MAR4]+[GLPlans]![APR4]+[GLPlans]![MAY4]+[GLPlans]![JUN4]) AS REESTYTD, [REESTYTD]-[ACTYTD] AS VAR4, +IIf([ACTYTD]=0,0,(([REESTYTD]/[ACTYTD])-1)) AS [%4], Sum([GLPlans]![JUL2]+[GLPlans]![AUG2]+[GLPlans]![SEP2]+[GLPlans]![OCT2]+[GLPlans]![NOV2]+[GLPlans]![DEC2]+[GLPlans]![JAN2]+[GLPlans]![FEB2]+[GLPlans]![MAR2]+[GLPlans]![APR2]+[GLPlans]![MAY2]+[GLPlans]![JUN2]) AS BUD, Sum([GLPlans]![JUL4]+[GLPlans]![AUG4]+[GLPlans]![SEP4]+[GLPlans]![OCT4]+[GLPlans]![NOV4]+[GLPlans]![DEC4]+[GLPlans]![JAN4]+[GLPlans]![FEB4]+[GLPlans]![MAR4]+[GLPlans]![APR4]+[GLPlans]![MAY4]+[GLPlans]![JUN4]) AS REEST INTO PCentre
FROM GLAccounts RIGHT JOIN ((Department LEFT JOIN cc ON Department.[PRFT CNTRE] = cc.[Cost Centre]) RIGHT JOIN GLPlans ON Department.[PRFT CNTRE] = GLPlans.[PRFT CNTRE]) ON GLAccounts.[ACC NO] = GLPlans.[ACC NO]
WHERE (((Department.[PRFT CNTRE])=[CC]![Cost Centre]))
GROUP BY GLPlans.[ACC NO], GLAccounts.[ACC DESC], GLAccounts.[ACC TYPE]
HAVING (((Sum([GLPLANS]![JUN5]))<>0)) OR (((Sum([GLPLANS]![JUN2]))<>0)) OR (((Sum([GLPLANS]![JUN4]))<>0)) OR (((Sum([GLPLANS]![JUL5]+[GLPLANS]![AUG5]+[GLPLANS]![SEP5]+[GLPLANS]![OCT5]+[GLPLANS]![NOV5]+[GLPLANS]![DEC5]+[GLPLANS]![JAN5]+[GLPLANS]![FEB5]+[GLPLANS]![MAR5]+[GLPLANS]![APR5]+[GLPLANS]![MAY5]+[GLPLANS]![JUN5]))<>0)) OR (((Sum([GLPlans]![JUL2]+[GLPlans]![AUG2]+[GLPlans]![SEP2]+[GLPlans]![OCT2]+[GLPlans]![NOV2]+[GLPlans]![DEC2]+[GLPlans]![JAN2]+[GLPlans]![FEB2]+[GLPlans]![MAR2]+[GLPlans]![APR2]+[GLPlans]![MAY2]+[GLPlans]![JUN2]))<>0)) OR (((Sum([GLPlans]![JUL4]+[GLPlans]![AUG4]+[GLPlans]![SEP4]+[GLPlans]![OCT4]+[GLPlans]![NOV4]+[GLPlans]![DEC4]+[GLPlans]![JAN4]+[GLPlans]![FEB4]+[GLPlans]![MAR4]+[GLPlans]![APR4]+[GLPlans]![MAY4]+[GLPlans]![JUN4]))<>0)) OR (((Sum([GLPlans]![JUL2]+[GLPlans]![AUG2]+[GLPlans]![SEP2]+[GLPlans]![OCT2]+[GLPlans]![NOV2]+[GLPlans]![DEC2]+[GLPlans]![JAN2]+[GLPlans]![FEB2]+[GLPlans]![MAR2]+[GLPlans]![APR2]+[GLPlans]![MAY2]+[GLPlans]![JUN2]))<>0)) OR (((Sum([GLPlans]![JUL4]+[GLPlans]![AUG4]+[GLPlans]![SEP4]+[GLPlans]![OCT4]+[GLPlans]![NOV4]+[GLPlans]![DEC4]+[GLPlans]![JAN4]+[GLPlans]![FEB4]+[GLPlans]![MAR4]+[GLPlans]![APR4]+[GLPlans]![MAY4]+[GLPlans]![JUN4]))<>0))
ORDER BY First(GLPlans.[PRFT CNTRE]), Last(GLPlans.[PRFT CNTRE]), GLPlans.[ACC NO];
Any help much appreciated.