PDA

View Full Version : Solved: Globally Change Report Fonts



Anne Troy
08-16-2004, 05:21 PM
Suppose I have 100 reports in my Access 2000 database.
Can someone write us some code (for insertion into the KB and to answer a Q at another site) that would just go in and change all the fonts to, for instance, Verdana font?

Thanks!!

Andy Pope
08-17-2004, 05:47 AM
Hi Dreamboat,

Access is not my forte but maybe this code will suffice.


Option Compare Database
Option Explicit
Sub AA()
ChangeReportFont "rptOne", "Veranda"
ChangeReportFont "rptTwo", "Arial"
ChangeReportFont "rptThree", "Tahoma"
End Sub
Sub ChangeReportFont(ReportName As String, NewFontname As String)

Dim objX As AccessObject
Dim objCurProject As Object
Dim objCnt As Control
Dim objReport As Report

On Error Resume Next
Set objCurProject = Application.CurrentProject
' Search for open AccessObject objects in AllReports collection.
For Each objX In objCurProject.AllReports
If objX.Name = ReportName Then
' open if not already
If Not objX.IsLoaded Then DoCmd.OpenReport objX.Name, acViewDesign
Set objReport = Application.Reports(objX.Name)
For Each objCnt In objReport.Controls
' change the font of all controls
objCnt.FontName = NewFontname
Next
' save and close report
With DoCmd
.Save acReport, objX.Name
.Close
End With
End If
Next

End Sub

Anne Troy
08-17-2004, 07:53 AM
Thanks, Andy!
I'm checking into it. :)

Anne Troy
08-17-2004, 08:10 AM
User replies:

This code did the trick. Thanks!!
Andy: Could you add this to our knowledgebase? That'd be TERRIFIC!!
Here's the link: http://www.vbaexpress.com/kb