Consulting

Results 1 to 4 of 4

Thread: Solved: Globally Change Report Fonts

  1. #1
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location

    Solved: Globally Change Report Fonts

    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!!
    ~Anne Troy

  2. #2
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    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

  3. #3
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Thanks, Andy!
    I'm checking into it.
    ~Anne Troy

  4. #4
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    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
    ~Anne Troy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •