更改Microsoft Access报告上所有控件上的字体

时间:2012-03-30 19:36:23

标签: ms-access vba fonts report

我有一个非常复杂的Microsoft Access报告。此报告针对多个客户运行。我想更改特定客户的报告(有吨)控件的子集**上的字体,但不会更改其他人的字体。由于字体设置在控件级别,是否可以以编程方式更改它?

**选择子集的标准将基于当前字体。例如,我想要更改当前使用Arial的所有控件上的字体。

2 个答案:

答案 0 :(得分:3)

怎么样:

Private Sub Report_Load()
If Me.OpenArgs = "1" Then
    ChangeFont Me
End If
End Sub


Sub ChangeFont(rpt As Report)
Dim ctl As Control

    For Each ctl In rpt.Controls
        If ctl.ControlType = acSubform Then
            ChangeFont ctl.Report
        ElseIf ctl.ControlType = acTextBox Then
            If ctl.FontName = "Calibri" Then

                 ctl.FontName = "Times"
            End If
        End If
    Next
End Sub

答案 1 :(得分:1)

您可以执行以下操作:

DoCmd.OpenReport "MyReport", acViewDesign, , , acHidden
For Each ctl In Reports.Item("AmbulanceServices")
  If ctl.FontName = "Arial" Then
    ctl.FontName = "Tahoma"
    ctl.FontSize = 10
  End If
Next
DoCmd.Save acReport, "MyReport"
相关问题