From: Sarah on 27 Mar 2010 21:00 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 27 Mar 2010 21:30 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 27 Mar 2010 22:01 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 27 Mar 2010 23:12 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 27 Mar 2010 23:15 > If Left(rpt.Name) = "rptGroup" Then Tut tut Jack. Brain fade? <g>
|
Next
|
Last
Pages: 1 2 3 Prev: How to show what record number you are on in form? Next: Office 2010 beta issues |