Change font on controls for all forms in an access database

I recently upgraded my laptop at work and for some reason the MS Serif Font is  now looking very poor. So I decided to change the fonts on all the forms in the databases I work on. So I came up with the following piece of code with some pointers from various sites. The font is hard coded. But could be easily be improved on. I used Arial as at least I knew it would be on the other computers that use the databases.  This only changes the font if it is not Arial as you can see from the code each form is opened up in design mode and then saved afterwards. I set the font on Labels, List Boxes, Text Boxes and Command Buttons. If you need other controls then add them to the the if statement as an or condition. I’ve used this in both Access 2003 and Access 2010.

Dim oForm As AccessObject
 Dim oActiveFrom As Form
 Dim oControl As Control
 Dim intCounter As Integer
 
 For intCounter = 0 To Application.CodeProject.AllForms.Count - 1
 Set oForm = Application.CodeProject.AllForms.Item(intCounter)
 If InStr(oForm.Name, "_") > 0 Then
 DoCmd.OpenForm FormName:=oForm.Name, View:=acDesign
 Set oActiveForm = Application.Screen.ActiveForm
 For Each oControl In oActiveForm.Controls
 If oControl.ControlType = acLabel Or oControl.ControlType = acListBox Or oControl.ControlType = acTextBox Or oControl.ControlType = acCommandButton Then
 If oControl.Properties.Item("FontName") <> "Arial" Then
 oControl.Properties.Item("FontName") = "Arial"
 End If
 End If
 Next
 DoCmd.Close objectType:=acForm, objectName:=oActiveForm.Name, Save:=acSaveYes
 End If
 Next
 
 Set oForm = Nothing
 Set oActiveForm = Nothing
 Set oControl = Nothing



 

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.