Globally Set Font For All Controls On All Forms

JamesJoey

Registered User.
Local time
Today, 08:10
Joined
Dec 6, 2010
Messages
628
I'm using the following code, in the On Load to set the font on all controls on the form:

Code:
 Public Function TextBoxProperties(frm As Form)
      Dim ctl As Control
     
     For Each ctl In frm.Controls
         
        If ctl.ControlType = acTextBox Or ctl.ControlType = acLabel Or ctl.ControlType = acCommandButton Or ctl.ControlType = acComboBox Then
            
            ctl.FontName = "Ebrima"
                        
        End If
            
     Next ctl
    
   On Error GoTo 0
   Exit Function
 End Function
 [CODE]
  
 Any time I want to change the font I need to open the module and change the value for ctl.FontName.
  
 Is the a way I can populate a table with font names and use the table to set these fonts?
 I can create a table with the font names but have no idea how to actually set the font to my forms.
  
 I've tried using the Them Fonts in Access but have some issues, like some controls not displaying the proper font. So, I've abandoned Theme Fonts.
  
 Any help will be appreciated,
 James
 
please use the code tags to preserve formatting which you will find on the advanced editor (the # button)

Code:
Public Function TextBoxProperties(frm As Form)
Dim ctl As Control

    For Each ctl In frm.Controls

        If ctl.ControlType = acTextBox Or ctl.ControlType = acLabel Or ctl.ControlType = acCommandButton Or ctl.ControlType = acComboBox Then

            ctl.FontName = "Ebrima"

        End If

    Next ctl

    On Error GoTo 0
    Exit Function
End Function
to answer your question, you could use dlookup to lookup the value from the table or a recordset. Assuming your table has many fonts and a 'default' yesno field for which only one font is selected

Code:
Dim ctl As Control
Dim FontStr as str
  
     FontStr=DLookup("FontName","tblFonts","Default=True")
     For Each ctl In frm.Controls
            ...
            ...
                ctl.FontName = FontStr
            ...
            ...
 
I've tried using the Them Fonts in Access but have some issues, like some controls not displaying the proper font. So, I've abandoned Theme Fonts.
I wonder what problems you were having with Theme Fonts?
 
The table I will create will only have about 4 to 6 fonts.
I understand the Dlookup but what I quite understand is the Yes/No check box.

First, where do I call the Dlookup function from.
Second, how do I tell the form what font name to pass?

The theme fonts...
I have a memo field that for some reason won't display the font in the theme.
I'm opening the form with a where condition to return only 1 record from a table.
Even when I open the continuous form populated with the same table, all records show the proper font for the memo field except for the record I display in the form with the where condition.
Odd.
I've deleted the memo field and put it back in with the same results.
I've even deleted the record and the same thing happens
 
A change to my last post.

The memo field is displaying the proper font in when all record are returned in the other form.
 
Any chance of uploading a db with just the problem memo and some sample records?
 
Now it's not working.

Yes, let me get it together and Ill upload the table and both forms.
 
Under the property sheet of the Memo textbox, go to the the Data tab and change the Text Format property to Plain Text. That will do it.
 
I can't even read it now. It shows all the formatting.

Why does the memo field on frmMemos display the proper font on all records except Grocery List??
 
Someone at some point applied formatting on it, or where the list originated had the formatting applied so that formatting is overriding the Theme Font. Work on some code to clean the data and remove the html tags and you should be fine.
 
I forgot to mention that my working form has more data in the memo field so I'm getting the formatting codes.
Yeas when I set it to Plain Text it works ok.
But, I have it set to Rich Text for a reason.

My confusion here is, I have 4 or 5 other forms that have a memo field set to Rich Text and there are no issues with them.

Again, open frmMemos and leave the text at Rich Text.
Then select each record (there are only 4) in secession.
You'll see that only the Grocery List record doesn't display the proper font.

How can that be when each other record on the form are using the same memo field??
 
Like mentioned, the formatting tags embedded in your memo, specifically the <font></font> tags, are overriding the Theme Fonts' font.

The reason why you can't see those tags is because you have set the Text Format property in the table as well. If you change that property in the table to Plain Text those font tags will become visible and you will be able to get rid of them.

Steps:
1. Create a copy of your table
2. Open the copy in design view and change the Text Format property of the Memo field to Plain Text. Save and Close.
3. At this point your Theme Fonts will work as normal.
4. Write code (or look for code) that will decode the html tags, i.e. to remove the html tags.
5. From now on, any control that uses this memo field can be set to Rich Text.

But remember that once you (or your users) apply any font type/font size formatting, it will create appropriate html font tags and override the Theme Fonts settings.
 
While I was waiting ;last night I did somw things on my own none of which worked.

I deleted the table.
Created a new table with a different name. I even named the 3 fields differently.
I left the memo field as Plain Text.
Created a new form based on the new table and paced the memo field on it and set it to Rich Text.
Nothing. I selected several Theme Fonts and none changed it.
So, I set the memo field on the form to Plain Text.
But in the html formatting there was no font names. So there wasn't anything there to override the Theme Font.

I'm real close to simply abandoning Access.
This is just one of many issues I have with the product.
]Granted some might be my fault but I will be willing to bet the majority oif them are Access issues.
I pend more time trying to figure pout workarounds than I do using my data.
It's getting very old.
 
I don't know, I don't have any subforms.

But, I do have several other forms based on different tables with memo fields set to Rich Text on both table and form levels.

And they work fine.
 
You've need to upload something that truly represents the problems you're having. If you say that other forms and tables are working and others aren't, upload those objects and tell me which ones work and which don't. And also ensure that it actually doesn't work in the cut-down version you upload.
 
I've found that after creating a new table and forms that when I have the memo field alone on the form the proper font doesn't display unless I close and reopen the form.
Also it seems to wok fine now if I have another field on the form along with the memo field.
Not sure how long this is going to last, though.
 
JamesJoey, when you upload a database you need to give instructions as to what to do, and where to look. It saves time and effort knowing what to look for.
 

Users who are viewing this thread

Back
Top Bottom