Change fontname of all objects

jakircevic

New member
Local time
Tomorrow, 05:48
Joined
Dec 28, 2009
Messages
4
Hi,

I would like to have the ability to change automatically the fontname used for all my objects (labels, text box etc..) in both my forms and reports.

Not being a programmer, I have googled my problem but could not find an answer. I have tried to declare the following global variable in a module but it does not work:

Public stdfont As String
For Each stdfont In Forms
Set stdfont = "arial"

Is there a simple way to achieve my goal?

Thank you!

Thierry
 
try;

Public Function ModificaFonteTodosForms(FontName As String, FontSize As String)
' Call ModificaFonteTodosForms("Tahoma","8")
On Error GoTo errlbl
Dim CorrerTodos As Single
Dim frm As AccessObject
Dim openFrm As Access.Form
Dim Controles As Access.Control
Dim CaixasTexto As Access.TextBox
CorrerTodos = Timer()
For Each frm In CurrentProject.AllForms
DoCmd.OpenForm frm.Name, acDesign
Set openFrm = Forms(frm.Name)
For Each Controles In openFrm
Controles.FontName = FontName
Controles.FontSize = FontSize
Next Controles
DoCmd.Save acForm, frm.Name
DoCmd.Close acForm, frm.Name
Next frm
CorrerTodos = Timer - CorrerTodos
Exit Function
errlbl:
If Not Err.Number = 438 Then
MsgBox Err.Number & " " & Err.Description
End If
Resume Next
End Function
 
Last edited:
Thank You Paulo.

I have added your code to a module called "ModificaFonteTodosForms".

But when I try to launch the code from a command button in a form I got the following error message: "The expression On Click you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name"

The code behind my command button is:

Private Sub Command0_Click(FontName As String)
ModificaFonteTodosForms ("Arial")
End Sub

Sorry I am just starting to learn how VBA works!

Thank you for your support

THierry
 
I found the way to make it work by changing the code to:

Private Sub Command0_Click()
ModificaFonteTodosForms "Arial"
End Sub

However I still have a problem: the fonts in my datasheets and my reports are not changed. Any idea how to make that work?

Thank you for your help!

Thierry
 
Last edited:
OK I could figure it out for the reports with the following code:

Public Sub ModifyAllReports(fontName As String)

On Error GoTo errlbl

Dim elapsed As Single
Dim rpt As AccessObject
Dim openRpt As Access.Report
Dim cntrl As Access.Control
Dim txtbx As Access.TextBox

elapsed = Timer()

For Each rpt In CurrentProject.AllReports
DoCmd.OpenReport rpt.Name, acDesign
Set openRpt = Reports(rpt.Name)
For Each cntrl In openRpt
cntrl.fontName = fontName
Next cntrl
DoCmd.Save acReport, rpt.Name
DoCmd.Close acReport, rpt.Name

Next rpt

elapsed = Timer - elapsed
MsgBox elapsed

Exit Sub

errlbl:
If Not Err.Number = 438 Then
MsgBox Err.Number & " " & Err.Description
End If
Resume Next

End Sub

But I still can't figure out how to modify the font of my datasheet. I suppose I would need to open them in normal view...but can it be done automatically (if form is continuous or single --> open in design view; if form is datasheet view --> open in normal view)?

Thierry
 
To modify the font of datasheet with:

Application.SetOption "Default Font Name", "Arial"
Application.SetOption "Default Font Size", 8
 

Users who are viewing this thread

Back
Top Bottom