INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Programmatically changing control properties

Programmatically changing control properties

(OP)

I've inherited a database in which the fonts for text boxes, command buttons, etc are very hard to read, including shadows and border colours that are unsightly.

Can I change all control properties in all forms in one go using code? I want simple Calibri 10, flat, no borders.

Thanks

RE: Programmatically changing control properties

(OP)

Thanks for the suggestion. As an example I've added a command button to one of the forms to run this.

CODE -->

Dim ctl As Control

For Each ctl In Forms.Item("Orders by Customer")
    If ctl.ControlType = acLabel Then
        ctl.FontName = "Calibri"
        ctl.FontSize = 10
    End If
   
Next ctl 

This does the job but on saving and reopening the old font reappears.

Any thoughts?

RE: Programmatically changing control properties

You can only save the changes if the form is opened in design mode. You must:
- open the form in design mode
- make the changes
- save and close the form

Duane
Hook'D on Access
MS Access MVP

RE: Programmatically changing control properties

Alternatively, you could use the code in the Form_Open event of each Form:

CODE -->

Private Sub Form_Open(Cancel As Integer)
 
Dim ctl As Control

For Each ctl In Me.Controls

    If ctl.ControlType = acLabel Then
        ctl.FontName = "Calibri"
        ctl.FontSize = 10
    End If
   
Next ctl

End Sub 

Note that replacing

For Each ctl In Forms.Item("Orders by Customer")

with

For Each ctl In Me.Controls

keeps you from changing the code for each Form...making it apply to the current Form.

Hope this helps!

There's always more than one way to skin a cat!

All posts/responses based on Access 2003/2007

RE: Programmatically changing control properties

(OP)

Thanks Duane and Missinglinq

Either way works fine but seems to mean going though each form separately. Is it possible to change properties of all forms in a single operation?

RE: Programmatically changing control properties

You could write code that loops through all forms and opens each in design mode. Then loop through the controls to make changes and save/close the form.

Duane
Hook'D on Access
MS Access MVP

RE: Programmatically changing control properties

Here's something I cobbled together years and years ago, that does what Duane is talking about...didn't post it originally because I had to schlep thru the almost 4400 archived files I have looking for it!

Create a new, temporary Form, put a Command Button on it, and use this code in the OnClick event of the button:

CODE -->

Dim rst As DAO.Recordset
   
    Dim ctl As Control
    
    Set rst = CurrentDb.OpenRecordset("SELECT [Name] FROM MSysObjects WHERE [Type] = -32768")
   
    With rst
      
      Do While Not .EOF
         
         DoCmd.OpenForm !Name, acDesign, , , , acHidden
         
         For Each ctl In Forms.Item(!Name)

           If ctl.ControlType = acLabel Then
             ctl.FontName = "Calibri"
             ctl.FontSize = 10
             ctl.ForeColor = vbGreen
           End If

         Next ctl

          DoCmd.Close acForm, !Name, acSaveYes
         
         .MoveNext
       
      Loop
      
        .Close
   
   End With 

Hope this helps!

There's always more than one way to skin a cat!

All posts/responses based on Access 2003/2007

RE: Programmatically changing control properties

Hate to leave anything to chance...

  1. Open the Form
  2. Click on the Command Button
  3. Copy my last Post
  4. Pass it on, if you find someone who needs it!

Hope this helps!

There's always more than one way to skin a cat!

All posts/responses based on Access 2003/2007

RE: Programmatically changing control properties

Also, I see I left the line

ctl.ForeColor = vbGreen

in there...you can delete it, of course...I just used it to make it easier when testing the code...small changes in Font Sizes are hard to detect, at my advanced age!

Hope this helps!

There's always more than one way to skin a cat!

All posts/responses based on Access 2003/2007

RE: Programmatically changing control properties

(OP)
Absolutely what I wanted, thanks very much! I can add in other control types and do the full job so much quicker than manually changing styles.

Very kind of you to hunt through your archives, I bet there's a lot of good stuff in the other 4399.

RE: Programmatically changing control properties

Glad we could help!

Hope this helps!

There's always more than one way to skin a cat!

All posts/responses based on Access 2003/2007

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close