Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Change Back Color in MS Access Forms via Code

Posted on 2004-04-19
10
Medium Priority
?
983 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 14

Accepted Solution

by:
JohnK813 earned 200 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
 

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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 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