Access

Change Font on Reports as Specified

Ease of Use

Intermediate

Version tested with

2000 

Submitted by:

Andy Pope

Description:

Changes the font in reports, all user-specified. 

Discussion:

So, maybe your company sold out to another, and now the whole company image changes, including the font used in print matter. You need to change the reports to use the new font. Use this code! 

Code:

instructions for use

			

Sub AA() ' ' Entry point routine to change font of specified reports ' ChangeReportFont "rptOne", "Veranda" ChangeReportFont "rptTwo", "Arial" ChangeReportFont "rptThree", "Tahoma" End Sub Sub ChangeReportFont(ReportName As String, NewFontname As String) ' ' Change the fontname of all controls within specified Report ' 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

How to use:

  1. Copy the code above.
  2. Open the Access database.
  3. Hit Alt+F11 to get to the Visual Basic Editor.
  4. From the menu, Insert-Module.
  5. Paste code into the code module.
  6. Modify the arguments within the AA() routine to match the required reports and the new font name.
 

Test the code:

  1. Go to Tools-Macro and double-click AA.
 

Sample File:

No Attachment 

Approved by Anne Troy


This entry has been viewed 117 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express