From: Sarah on
hi Allen: This worked great, but first I had to make 2 changes:
a) I had to check that Reports.Count > 0 (because sometimes none of the
reports are open when the code is run, so I end up considering Reports(-1) in
the 'IF' statement).
b) I had to add 'STEP -1' to the 'FOR' statement.

Sarah

"Allen Browne" wrote:

> Loop backwards (since you're reducing the count) through the Reports
> collection:
>
> Dim i As Integer
> For i = Reports.Count -1 To 0
> If Reports(i).Name Like "rptGroup*" Then
> DoCmd.Close acReport, Reports(i).Name
> End If
> Next
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
>
> "Sarah" <Sarah(a)discussions.microsoft.com> wrote in message
> news:F701D373-D972-4612-ACA2-A77C135F80ED(a)microsoft.com...
> > I have VBA where I need to close any reports that are currently open. All
> > of
> > the reports in question have names starting with "rptGroup" followed by 2
> > more characters. There are up to 17 of these reports that could be open,
> > so
> > I use this coding to be sure I catch any open ones;
> >
> > DoCmd.Close acReport, "rptGroup01"
> > DoCmd.Close acReport, "rptGroup02"
> > DoCmd.Close acReport, "rptGroup03"
> > ......
> > DoCmd.Close acReport, "rptGroup17"
> >
> > is there a way to more simply close all reports LIKE "rptGroup*"?
> >
> > thanks in adavance
> > Sarah
>
> .
>
From: Allen Browne on
Yes: that makes sense.

Glad you were able to put the idea to use.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.


"Sarah" <Sarah(a)discussions.microsoft.com> wrote in message
news:EECE56C7-14A5-4CA7-BBE8-7C78F413FDD5(a)microsoft.com...
> hi Allen: This worked great, but first I had to make 2 changes:
> a) I had to check that Reports.Count > 0 (because sometimes none of the
> reports are open when the code is run, so I end up considering Reports(-1)
> in
> the 'IF' statement).
> b) I had to add 'STEP -1' to the 'FOR' statement.
>
> Sarah
>
> "Allen Browne" wrote:
>
>> Loop backwards (since you're reducing the count) through the Reports
>> collection:
>>
>> Dim i As Integer
>> For i = Reports.Count -1 To 0
>> If Reports(i).Name Like "rptGroup*" Then
>> DoCmd.Close acReport, Reports(i).Name
>> End If
>> Next
>>
>> --
>> Allen Browne - Microsoft MVP. Perth, Western Australia
>> Tips for Access users - http://allenbrowne.com/tips.html
>> Reply to group, rather than allenbrowne at mvps dot org.
>>
>>
>> "Sarah" <Sarah(a)discussions.microsoft.com> wrote in message
>> news:F701D373-D972-4612-ACA2-A77C135F80ED(a)microsoft.com...
>> > I have VBA where I need to close any reports that are currently open.
>> > All
>> > of
>> > the reports in question have names starting with "rptGroup" followed by
>> > 2
>> > more characters. There are up to 17 of these reports that could be
>> > open,
>> > so
>> > I use this coding to be sure I catch any open ones;
>> >
>> > DoCmd.Close acReport, "rptGroup01"
>> > DoCmd.Close acReport, "rptGroup02"
>> > DoCmd.Close acReport, "rptGroup03"
>> > ......
>> > DoCmd.Close acReport, "rptGroup17"
>> >
>> > is there a way to more simply close all reports LIKE "rptGroup*"?
>> >
>> > thanks in adavance
>> > Sarah
>>
>> .
>>