Solved

Change Back Color in MS Access Forms via Code

Posted on 2004-04-19
10
966 Views
Last Modified: 2013-12-26
I am using ms access and would like to know how I can change the backcolor (or even font) of all forms in a db using code (eg function)?

Below is what I got so far. Dont know if I'm on the right track:

Function changeBackColor()

Dim db As Database
Dim frm As Document

Set db = CurrentDb()

For Each frm In db.Containers("Forms").Documents
   'Dont know what to do here???
Next frm

End Function
0
Comment
Question by:bfausti
  • 4
  • 4
10 Comments
 
LVL 14

Expert Comment

by:JohnK813
ID: 10860663
Me.Detail.BackColor = RGB(x,y,z)

where x, y, and z are red, green, and blue values (respectively) between 0 and 255.

As for changing the font - you'll probably need to do that for each object, using .FontName, .FontSize...
0
 
LVL 14

Expert Comment

by:JohnK813
ID: 10860685
I'm sorry - just reread the question.  You'll want to put

frm.Detail.BackColor = RGB(x,y,z)

in your For Each loop.

You could theoretically put another For Each loop inside that loop to cycle through all of the controls on the current form and change the font:

For Each frm In db.Containers("Forms").Documents
   frm.Detail.BackColor = RGB(255,0,0) 'red
  For Each ctrl in frm.Controls 'check my syntax here
    ctrl.FontName = "Times" 'or whatever
    ctrl.FontSize = 14
  Next ctrl
Next frm
0
 

Author Comment

by:bfausti
ID: 10866663
Sorry this does not work as frm is the object type document and does not contain the detail property. Please advise?
0
 
LVL 14

Accepted Solution

by:
JohnK813 earned 50 total points
ID: 10868131
Let me know if this works:

For Each frm In Forms
   frm.Detail.BackColor = RGB(255,0,0) 'red
  For Each ctrl in frm 'or frm.Controls
    ctrl.FontName = "Times" 'or whatever
    ctrl.FontSize = 14
  Next ctrl
Next frm

Here you're using the "Forms" collection.  One note: not all objects have the .FontName property, so you may have to play around with that a bit.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:bfausti
ID: 10868300
Sorry still no good, this problem is drving me crazy!
0
 

Author Comment

by:bfausti
ID: 10868849
I worked it out! You have to open each form in design view to make changes to it, otherwise Access doesn't see the form. There might be a better way, but this works for me!

    Dim db As Database
    Dim frm As Document
    Dim frmColor As Long

    frmColor = 9029041
   
    Set db = CurrentDb()
    For Each frm In db.Containers("Forms").Documents
        DoCmd.OpenForm frm.Name, acDesign
        Screen.ActiveForm.Detail.BackColor = frmColor
        DoCmd.Close acForm, frm.Name, acSaveYes
    Next frm

Haven't got the font yet but I'm still trying. Thanks for your help anyway.
0
 
LVL 14

Expert Comment

by:JohnK813
ID: 10869088
That's right... forgot that the forms had to be open for my method to work.

Have you tried

For Each ctrl in Screen.ActiveForm.Controls

? (don't know if this works - I'm just curious myself)
0
 

Author Comment

by:bfausti
ID: 10869154
Yes it works thanks!
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now