Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Change Back Color in MS Access Forms via Code

Posted on 2004-04-19
10
Medium Priority
?
985 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Suggested Courses

885 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