Solved

Change Back Color in MS Access Forms via Code

Posted on 2004-04-19
10
970 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 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