From: Sarah on
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
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: Jack Leach dymondjack at hot mail dot on
Dim rpt As Report
For Each rpt In Reports
If Left(rpt.Name) = "rptGroup" Then
DoCmd.Close acReport, rpt.Name
End If
Next rpt


hth
--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)



"Sarah" wrote:

> 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: Sarah on
thanks to Jack and Allen for some great answers.
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: Stuart McCall on
> If Left(rpt.Name) = "rptGroup" Then

Tut tut Jack. Brain fade? <g>