vba 更改 Microsoft Access 报告上所有控件的字体
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9949398/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change font on all controls on Microsoft Access report
提问by James Hill
I have a very complex Microsoft Access report. This report is run for multiple customers. I would like to change the font on a subset** of controls on the report (there are tons) for a particular customer, but not for others. Since the font is set at the control level, is it possible to change it programatically?
我有一个非常复杂的 Microsoft Access 报告。此报告针对多个客户运行。我想为特定客户更改报表控件子集**(有很多)的字体,但不为其他客户更改字体。由于字体是在控件级别设置的,是否可以通过编程方式更改它?
**The criteria that selects the subset would be based on the current font. For example, I would want to change the font on all controls which currently use Arial.
**选择子集的标准将基于当前字体。例如,我想更改当前使用 Arial 的所有控件的字体。
回答by Fionnuala
How about:
怎么样:
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
回答by ron tornambe
You can do something like the following:
您可以执行以下操作:
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"