Solved

Change Back Color in MS Access Forms via Code

Posted on 2004-04-19
10
969 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

772 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