VBA - Add footer to 200 reports

M

MVP - WannaB

I have about 200 reports that I need to add "Confidential" to the footer of.
Is there a way that I can do this with an automated function?
Thanks in advance for your help.
 
J

Jeff Boyce

Let's see, is that ALL of your reports, or just 200 of some larger number?
If it isn't ALL, how would you inform your automated function which ones to
add it to?

More info, please...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
J

Jeff Boyce

PS ... by the time you're done developing this function, testing it, and
inspecting to make sure it worked, you probably could have long before
complete the 'manual' task of doing this!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
F

fredg

I have about 200 reports that I need to add "Confidential" to the footer of.
Is there a way that I can do this with an automated function?
Thanks in advance for your help.

Footer of? As in Report Footer?
Some Reports?
Add one label to one report.
Select the label and copy it.

Open each report in turn and paste the label into the Report Footer
section.
Move it where you want it.

All reports?
The following will add a label to each report footer in your database
(if the report has a report footer) and position it 2 inches from the
left and 1/2-inch down from the top of the section. Change those
positions as needed.

Are you sure the label will fit in the same position on all reports?
It's up to you to know, for each report, if that position will work
without messing up your report.
Note: All measurements are in Twips, 1440 per inch.

Watch out for word wrap on the longer lines.


Copy and Paste the following into a Module.

Public Sub AddReportControl()
Dim db As DAO.Database
Dim doc As Document
Set db = CurrentDb
Dim ctl As Control

For Each doc In db.Containers("reports").Documents
DoCmd.OpenReport doc.Name, acViewDesign, , , acHidden
On Error GoTo NoFooter
Application.CreateReportControl doc.Name, acLabel, acFooter, ,
"Confidential", 1440 * 2, 0.5 * 1440, 2880, 1440
For Each ctl In Reports(doc.Name).Section(2).Controls
If TypeOf ctl Is Label Then
If ctl.Caption = "Confidential" Then
' Re-size the control within the section and set it's
fontsize to 14
ctl.Width = 1.5 * 1440
ctl.Height = 0.3 * 1440
ctl.fontsize = 14
End If
End If
Next ctl
CloseReport:
DoCmd.Close acReport, doc.Name, acSaveYes
Next doc

Exit_Sub:
Exit Sub
NoFooter:
Resume CloseReport

End Sub

Change the positioning as needed.

Perhaps Copy and Paste would be more efficient as you can easily
miss-position the label on the different reports.
 
M

MVP - WannaB

I originally posted this Friday night, but accidently posted "reply to
sender", and should have posted "reply to group"

200 of a larger number, some are sub-reports and those would be excluded.
I can pull a list of report names from the system table and weed out those
are will not need to be modified.
I understand this could take a good deal of time to create and debug, but
the more I work with VBA the better I understand it, and that is one of my
goals.
===============================
PS ... by the time you're done developing this function, testing it, and
inspecting to make sure it worked, you probably could have long before
complete the 'manual' task of doing this!

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
M

MVP - WannaB

This looks very interesting. However where I would not be adding that
footer to all Reports, could I restructure the code to use a user table that
I would build from a query on reports in the systems table. I would then
remove the few reports from that user table that did not need the footer. I
MIGHT BE OFF A LOT. The code looks like you are referring to a container
where report names are stored and I think that might be different then the
systems table that I was referring to please advise how I might retrieve a
list of report names and any other fields needed from that container?
THANKS SO MUCH FOR YOUR TIME AND ASSISTANCE
==========================================
I have about 200 reports that I need to add "Confidential" to the footer
of.
Is there a way that I can do this with an automated function?
Thanks in advance for your help.

Footer of? As in Report Footer?
Some Reports?
Add one label to one report.
Select the label and copy it.

Open each report in turn and paste the label into the Report Footer
section.
Move it where you want it.

All reports?
The following will add a label to each report footer in your database
(if the report has a report footer) and position it 2 inches from the
left and 1/2-inch down from the top of the section. Change those
positions as needed.

Are you sure the label will fit in the same position on all reports?
It's up to you to know, for each report, if that position will work
without messing up your report.
Note: All measurements are in Twips, 1440 per inch.

Watch out for word wrap on the longer lines.


Copy and Paste the following into a Module.

Public Sub AddReportControl()
Dim db As DAO.Database
Dim doc As Document
Set db = CurrentDb
Dim ctl As Control

For Each doc In db.Containers("reports").Documents
DoCmd.OpenReport doc.Name, acViewDesign, , , acHidden
On Error GoTo NoFooter
Application.CreateReportControl doc.Name, acLabel, acFooter, ,
"Confidential", 1440 * 2, 0.5 * 1440, 2880, 1440
For Each ctl In Reports(doc.Name).Section(2).Controls
If TypeOf ctl Is Label Then
If ctl.Caption = "Confidential" Then
' Re-size the control within the section and set it's
fontsize to 14
ctl.Width = 1.5 * 1440
ctl.Height = 0.3 * 1440
ctl.fontsize = 14
End If
End If
Next ctl
CloseReport:
DoCmd.Close acReport, doc.Name, acSaveYes
Next doc

Exit_Sub:
Exit Sub
NoFooter:
Resume CloseReport

End Sub

Change the positioning as needed.

Perhaps Copy and Paste would be more efficient as you can easily
miss-position the label on the different reports.
 
C

Clif McIrvin

MVP - WannaB said:
This looks very interesting. However where I would not be adding that
footer to all Reports, could I restructure the code to use a user
table that
I would build from a query on reports in the systems table. I would
then
remove the few reports from that user table that did not need the
footer. I
MIGHT BE OFF A LOT. The code looks like you are referring to a
container
where report names are stored and I think that might be different then
the
systems table that I was referring to please advise how I might
retrieve a
list of report names and any other fields needed from that container?
THANKS SO MUCH FOR YOUR TIME AND ASSISTANCE

There are lots of examples "out there" ... here are a couple of links
that have a lot of good information for Access students.

For your specific question, I believe that Arvin Meyer's "Document
Database" code will get you started:
http://www.accessmvp.com/Arvin/Index.htm

http://www.accessmvp.com

has links to lots of informative reading!
 
Top