I am using Access 2007. I want to use VBA code that will programmatically run an Access Report a series of times. Something like this:
Dim eid$(5)
eid$(1)="001":eid$(2)="021":eid$(3)="043":eid$(4)="052":eid$(5)="067"
for i=1 to 5
Forms![frmWork]!txtEid=eid$(i)
DoCmd.OpenReport "rptEmployees", acViewPreview
next i
The report uses a query that contains:
WHERE (employee.eid)=Forms![frmWork]!txtEid
After the report appears on the screen I want it to immediately close - without the user clicking Close Print Preview - and return to the VBA loop so another report can be generated.
You may wonder why I'm doing this? Let's just say I'm experimenting.
My question is...how can I get the report to close? Is there an event that occurs when a report has finished printing?
If I knew how many records (n) were output by the query I could put a counter in the report's Detail_Print() code. When the counter reached n I could have the report close. Can I determine how many records are in the query results when the report opens?
Thanks very much.