change properties of all reports

P

PC User

Part of my code works, but recently I wanted to change more report
properties. Access 2007 doesn't have a lot of explaination of the use
of properties. This is my "change properties of all reports" code:
=================================
Public Function ChangeReports()
Dim db As Database, c As Container, d As Document, r As Report
Set db = CurrentDb
Set c = db.Containers("Reports")
For Each d In c.Documents
DoCmd.OpenReport d.NAME, acViewDesign
Set r = Reports(d.NAME)
r.DefaultView = 1
r.PopUp = True
'r.PageHeaderSection.BackColor = RGB(255, 255, 255)
'r.Detail.BackColor = RGB(255, 255, 255)
'r.PageFooterSection.BackColor = RGB(255, 255, 255)
'r.Picture = (none)
DoCmd.Close acReport, d.NAME, acSaveYes
Next d
End Function
=================================
The lines that I made into comments get errors; so there must be some
better way of writing these code lines. Has anyone done this before?

Thanks,
PC
 
D

Douglas J. Steele

Try

r.Section(acPageHeader).BackColor = RGB(255, 255, 255)
r.Section(acDetail).BackColor = RGB(255, 255, 255)
r.Section(acPageFooter).BackColor = RGB(255, 255, 255)
r.Picture = "(none)"
 
M

Marshall Barton

PC said:
Part of my code works, but recently I wanted to change more report
properties. Access 2007 doesn't have a lot of explaination of the use
of properties. This is my "change properties of all reports" code:
=================================
Public Function ChangeReports()
Dim db As Database, c As Container, d As Document, r As Report
Set db = CurrentDb
Set c = db.Containers("Reports")
For Each d In c.Documents
DoCmd.OpenReport d.NAME, acViewDesign
Set r = Reports(d.NAME)
r.DefaultView = 1
r.PopUp = True
'r.PageHeaderSection.BackColor = RGB(255, 255, 255)
'r.Detail.BackColor = RGB(255, 255, 255)
'r.PageFooterSection.BackColor = RGB(255, 255, 255)
'r.Picture = (none)
DoCmd.Close acReport, d.NAME, acSaveYes
Next d
End Function
=================================
The lines that I made into comments get errors; so there must be some
better way of writing these code lines. Has anyone done this before?


The Picture property has a string value so you need to
enclose it in quotes:
r.Picture = "(none)"

The other lines look syntatically correct. Are you sure
that those are the section names? Instead of using section
names, I prefer:
r.Section(3).BackColor = RGB(255, 255, 255)
r.Section(0).BackColor = RGB(255, 255, 255)
r.Section(4).BackColor = RGB(255, 255, 255)

You should tell us what error you received so we don't have
to guess at what might be wrong.
 
P

PC User

Thank you Douglas J. Steele and thank you Marshall Barton for your
replies. I applied your suggestions and the same error returned for
both.

Run-time error '2467'
The section number you entered is invalid.

I hope there's some more alternatives.

~~~ PC
 
M

Marshall Barton

PC said:
Thank you Douglas J. Steele and thank you Marshall Barton for your
replies. I applied your suggestions and the same error returned for
both.

Run-time error '2467'
The section number you entered is invalid.


You have to either create the Page Header/Footer sections
or, for your global modify routine, trap and ignore the
error. I don't like using On Error Resume Next, but it
might be good enough in this case.
 
P

PC User

Your right Marshall. I put the error trap your gave me and now it
works. I guess ordinarally all reports should have a header and
footer. However, see as there are too many forms to check manually,
I'd rather process the errors. The code now works great.

Thanks,
PC
 
L

Larry Linson

PC User said:
Your right Marshall. I put the error trap your gave me and now it
works. I guess ordinarally all reports should have a header and
footer. However, see as there are too many forms to check manually,
I'd rather process the errors. The code now works great.

No, all reports do not have to have a PageHeader and a PageFooter, but any
report in which you wish to display and/or refer to the PageHeader or
PageFooter must have one.

Larry Linson
Microsoft Office Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top