473,569 Members | 2,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form Backgroud colors

My boss wants to be able to set the background color of all forms to
one color that he selects on our Configuration form..
I'd rather not add a function to every form I have and wondered if it
could be done by going through the forms collections. Here is my code
but I need help addressing each from using a variable name. Please
help me with the syntax.

Private Sub UpdateFormColor s(NewColor as long)

Dim obj As AccessObject, dbs As Object
Dim CurrentFormName As String

Set dbs = Application.Cur rentProject
For Each obj In dbs.AllForms
CurrentFormName = obj.Name

' This line doesn't work - how do I use the variable name
Forms!CurrentFo rmName.Detail.B ackColor = NewColor

Next obj

End Sub
'Should the forms be open or closed.
Hank Reed

Dec 1 '05 #1
7 1627
One could write code to do this, (and I expect we will see examples of
that PDQ) but I wouldn't recommend it.
What if the common background color is the same color as the foreground
color of a control whose background is transparent?
Perhaps, instead of programming the form backcolor change you could
program your boss to find something worthwhile and sensible to do with
his/her time?

Dec 1 '05 #2
Lyle Fairfield wrote:
Perhaps, instead of programming the form backcolor change you could
program your boss to find something worthwhile and sensible to do with
his/her time?


What kind of a boss micromanages things to such a level, any way? What
an ass-wipe! Hank's boss, I mean, I don't mean you, Hank! 8)
--
Tim http://www.ucs.mun.ca/~tmarshal/
^o<
/#) "Burp-beep, burp-beep, burp-beep?" - Quaker Jake
/^^ "Whatcha doin?" - Ditto "TIM-MAY!!" - Me
Dec 1 '05 #3
Lyle,
Thanks for the keen observations about my boss. ;-)

Actually his reasons are pretty good. We have the same
database code installed at two different geographical locations but
with two different bckends. Sometimes he wants to have them both open
at the same time.
It was me who cautioned him that it would be easy to lose
track of which one he was looking at. I don't like having two things
look exactly alike when they are actually dfferent. I felt that having
a different background color for each site would keep him from getting
confused. Sometimes our job is to protect our bosses from themselves.
Where I need help is changing the backgound color of all
forms though some itterative method when a new color is selected. My
first (dumb) idea was to have a function on each form that looked up
the color from the Configuration Table. Nahhhh.
I'm using Access 2000.
Thanks,
Hank

Dec 1 '05 #4
One could put code in the load or open event of all forms to change the
backcolor of the detail section of the form.
If one has a million froms this could be quite a chore. I looked up my
"Standardiz e Forms" Code to see if this could be adapted to do this and
I believe it can. But the code was written in the days of Access 97
and needs some revision to work in Access >= 2000. That will take a
little "spare time" which may or may not happen soon.
In the meantime here is another suggestion. I change the application
title sometimes so that users have some information in front of them
about what they are working on. The code is very simple and they don't
have to remember what red stands for; the words are right there:
Option Explicit

Private Declare Function SetWindowText Lib "user32" _
Alias "SetWindowTextA " _
(ByVal hwnd As Long, ByVal lpString As String) As Long

Public Sub DisplayAppTitle (ByVal Title As String)
SetWindowText hWndAccessApp, Title
End Sub

Sub test()
DisplayAppTitle "Patagonia"
End Sub

Assuming your backends has some distinguishing data that could be
queried on application open and used to specify this app title which
would be always there.

Dec 1 '05 #5
A little later

Well if you HAVE to revise a million forms you might be able to modify
this code to do it; as I mentioned previously it was written for AC97
and so many there are UDFs in it which are now redundant. In 1998 I
tested it a lot but in 2005 I've tested it ONLY once. So if you plan to
use it, please, do so on a throw away copy of your db until you feel
safe about it.

Public Sub StandardizeTheF orms()
Dim BaseName As String
Dim Ctl As Control
Dim Frm As Form
Dim Increment As Long
Dim NewIterator As Long
Dim NewName As String
Dim NewNames As New Collection
Dim Obj As AccessObject
Dim OldIterator As Long
Dim OldName As String
Dim OldNames As New Collection
Dim Old_Name As String
Dim Old_Names As New Collection
Dim Prefix As String
Dim StatusBarVisibl e As Boolean
Dim Substance As String
On Error Resume Next
StatusBarVisibl e = GetOption("Show Status Bar")
SetOption "Show Status Bar", True
Echo False
For Each Obj In Application.Cur rentProject.All Forms
With Obj
DoCmd.Close acForm, .FullName
DoCmd.OpenForm .FullName, acDesign
Set Frm = Forms(.FullName )
With Frm
.HasModule = True
For Each Ctl In .Controls
With Ctl
Prefix = ""
OldName = .Name
Old_Name = strTran(OldName , " ", "_")
SysCmd acSysCmdSetStat us, "Processing " &
OldName & " ..."
Select Case .ControlType
Case acLabel
Prefix = "lbl"
Substance = .Caption
Case acTextBox
Prefix = "txt"
Substance = .ControlSource
If Len(Substance) = 0 Then Substance =
OldName
Case acComboBox
Prefix = "cbo"
Substance = .ControlSource
If Len(Substance) = 0 Then Substance =
OldName
Case acListBox
Prefix = "lst"
Substance = .ControlSource
If Len(Substance) = 0 Then Substance =
OldName
Case acCheckBox
Prefix = "chk"
Substance = .ControlSource
Case acSubform
Prefix = "sub"
Substance = .SourceObject
Case acCommandButton
Prefix = "cmd"
Substance = .Caption
Case acImage
Prefix = "img"
Substance = .Name
End Select
If Len(Prefix) <> 0 Then
If Len(Substance) = 0 Then Substance =
OldName
Substance = AlphaNumericOnl y(Substance)
BaseName = Prefix &
Left(AlphaNumer icOnly(Substanc e), 249)
Do While Mid(BaseName, 1, 3) =
Mid(BaseName, 4, 3)
BaseName = Mid(BaseName, 4)
Loop
Increment = 0
Do
Err = 0
.Name = BaseName
Increment = Increment + 1
BaseName = BaseName & CStr(Increment)
Loop Until Err = 0
NewName = .Name
With OldNames
If .Count = 0 Then
.Add OldName
Old_Names.Add Old_Name
NewNames.Add NewName
Else
For OldIterator = 1 To .Count
If Len(OldName) <
Len(.Item(OldIt erator)) Then
Exit For
End If
Next OldIterator
If OldIterator > .Count Then
.Add OldName
Old_Names.Add Old_Name
NewNames.Add NewName
Else
.Add OldName, , OldIterator
Old_Names.Add Old_Name, ,
OldIterator
NewNames.Add NewName, ,
OldIterator
End If
End If
End With
End If
End With
Next Ctl
With NewNames
For NewIterator = 1 To .Count
NewName = .Item(NewIterat or)
OldName = OldNames(NewIte rator)
SysCmd acSysCmdSetStat us, "Renaming " & OldName
& " to " & NewName & " ..."
Old_Name = Old_Names(NewIt erator)
FindandReplacei nModule Frm.Module, OldName,
NewName
FindandReplacei nModule Frm.Module, Old_Name,
NewName
With OldNames
If .Count > NewIterator Then
For OldIterator = NewIterator + 1 To
..Count
OldName =
strTran(.Item(O ldIterator), OldName, NewName)
If OldName <> .Item(OldIterat or)
Then
.Remove OldIterator
.Add OldName, , , OldIterator -
1
End If
Old_Name =
strTran(.Item(O ldIterator), Old_Name, NewName)
If Old_Name <> .Item(OldIterat or)
Then
.Remove OldIterator
.Add Old_Name, , , OldIterator
- 1
End If
Next OldIterator
End If
End With
Next NewIterator
End With
Set NewNames = Nothing
Set OldNames = Nothing
Set Old_Names = Nothing
SysCmd acSysCmdSetStat us, "Modifying Properties" & "
...."
.MaxButton = False
.AutoCenter = True
.AutoResize = True
SysCmd acSysCmdSetStat us, "Modifying Code" & " ..."
ModifyCode .Module
DeleteDoubleBla nkLinesinModule .Module
OrderControls Frm
DoCmd.Close acForm, .Name, acSaveYes
End With
End With
Next Obj
Set Ctl = Nothing
Set Frm = Nothing
SysCmd acSysCmdClearSt atus
SetOption "Show Status Bar", True
Echo True
End Sub

Private Sub ModifyCode(ByRe f Mdl As Module)
Const EndColumn As Byte = 255
Const ProcCode _
= " With DoCmd" & vbCrLf _
& " .Restore" & vbCrLf _
& " .RunCommand acCmdSizeToFitF orm" & vbCrLf _
& " End With"
Const ProcName As String = "Form_Load"
Const StartColumn As Byte = 0
Const SubPrefix As String = "Private Sub "
Const SubSuffix As String = "End Sub"
Const Trigger As String = "RunCommand acCmdSizeToFitF orm"
Dim EndLine As Long
Dim StartLine As Long
On Error Resume Next
With Mdl
Err = 0
StartLine = .ProcBodyLine(P rocName, vbext_pk_Proc)
' err 35 returned when proc can't be found
If Err = 35 Then
StartLine = .CountOfLines + 1
.InsertLines StartLine, SubSuffix
.InsertLines StartLine, ProcCode
.InsertLines StartLine, SubPrefix & ProcName
.InsertLines StartLine, ""
Else
StartLine = .ProcBodyLine(P rocName, vbext_pk_Proc)
EndLine = StartLine + .ProcCountLines (ProcName,
vbext_pk_Proc) - 1
If Not _
(.Find(Trigger, StartLine + 1, _
StartColumn, EndLine - 1, EndColumn)) Then
.InsertLines EndLine - 1, ProcCode
End If
End If
End With
End Sub

Private Sub DeleteDoubleBla nkLinesinModule (ByRef Mdl As Module)
Dim Line As Long
On Error Resume Next
With Mdl
For Line = .CountOfLines To 2 Step -1
If Len(AlphaNumeri cOnly(.Lines(Li ne - 1, 2))) = 0 Then
..DeleteLines Line, 1
Next Line
End With
End Sub

Private Sub OrderControls(B yRef Frm As Form)
Dim Col As New Collection
Dim ColIterator As Long
Dim CtlInCol As Control
Dim CtlInForm As Control
Dim CtlName As String
Dim Prp As Property
Dim VarCtl As Variant
On Error Resume Next
For Each CtlInForm In Frm.Controls
SysCmd acSysCmdSetStat us, "Processing " & CtlInForm.Name & "
...."
With Col
If .Count = 0 Then
.Add CtlInForm
Else
For ColIterator = 1 To .Count
Set CtlInCol = .Item(ColIterat or)
If (CtlInForm.Top < CtlInCol.Top) _
Or ((CtlInForm.Top = CtlInCol.Top) _
And (CtlInForm.Left <= CtlInCol.Left)) Then
.Add CtlInForm, , ColIterator
Exit For
End If
Next ColIterator
End If
If ColIterator = .Count + 1 Then .Add CtlInForm
End With
Next CtlInForm
For Each VarCtl In Col
Set CtlInCol = VarCtl
With CtlInCol
CtlName = .Name
Set CtlInForm = CreateControl(F rm.Name, .ControlType,
..Section, , , 0, 0, 1, 1)
For Each Prp In CtlInCol.Proper ties
With Prp
CtlInForm.Prope rties(.Name) = .Value
End With
Next Prp
End With
CtlInForm.Name = "Tmp" & CtlName
DeleteControl Frm.Name, CtlName
CtlInForm.Name = CtlName
Next VarCtl
Set CtlInCol = Nothing
Set Col = Nothing
Set CtlInForm = Nothing
Set Prp = Nothing
End Sub

Private Function strTran( _
ByVal ReplaceIn As String, _
ByVal ReplaceWhat As String, _
ByVal ReplaceWith As String, _
Optional ByVal CompareMethod As Long = vbTextCompare) As String
Dim Position As Long
On Error Resume Next
Position = InStr(1, ReplaceIn, ReplaceWhat, CompareMethod)
Do While Position <> 0
strTran = strTran & Left(ReplaceIn, Position - 1) & ReplaceWith
ReplaceIn = Mid(ReplaceIn, Position + Len(ReplaceWhat ))
Position = InStr(1, ReplaceIn, ReplaceWhat, CompareMethod)
Loop
strTran = strTran & ReplaceIn
End Function

Private Function AlphaNumericOnl y(ByVal s As String) As String
Dim a() As Byte
Dim b As Byte
Dim v As Variant
On Error Resume Next
a = StrConv(s, vbFromUnicode)
For Each v In a
If v > 47 And v < 58 Then
AlphaNumericOnl y = AlphaNumericOnl y & Chr(v)
Else
b = v Or 32
If b > 96 And b < 123 Then AlphaNumericOnl y =
AlphaNumericOnl y & Chr(v)
End If
Next v
End Function

Private Sub FindandReplacei nModule( _
ByRef Mdl As Module, _
ByVal ReplaceWhat As String, _
ByVal ReplaceWith As String)
Dim EndColumn As Long
Dim EndLine As Long
Dim StartColumn As Long
Dim StartLine As Long
Dim strLine As String
Dim strLeft As String
Dim strRight As String
On Error Resume Next
If (Len(ReplaceWit h) = 0) Or (Len(ReplaceWha t) = 0) Or (ReplaceWhat
= ReplaceWith) Then Exit Sub
With Mdl
Do While .Find(ReplaceWh at, StartLine, StartColumn, EndLine,
EndColumn, True)
strLine = .Lines(StartLin e, 1)
strLeft = Mid$(strLine, 1, StartColumn - 1)
strRight = Mid$(strLine, EndColumn)
strLine = strLeft + ReplaceWith + strRight
.ReplaceLine StartLine, strLine
StartColumn = StartColumn + Len(ReplaceWith )
EndLine = 0
EndColumn = 0
Loop
.Application.Ru nCommand acCmdCompileLoa dedModules
End With
End Sub

Dec 1 '05 #6

I'm not sure I'd use a configuration table for this. At least, not
one that was user modifiable! It's *really* easy for a user to change
the code to something that makes text disappear, or do other weird
things.

But if you want to do this, in the form load event (and yes, you'll
have to do this in every form), look at the path (or connect
statement) where the backend is, and use the Me.Detail.Backc olor
statement to change the background color of the form.

Below is an example using a SQL Server backend:

Dim mydb As DAO.Database
Dim myrst As DAO.Recordset
Const strSQL As String = _
"SELECT Connect " & _
"FROM MSysObjects " & _
"WHERE [Name]='SomeBackendTa ble'"
Set mydb = CurrentDb
Set myrst = mydb.OpenRecord set(strSQL, , dbOpenForwardOn ly)
If Not myrst.EOF And Not myrst.BOF Then
Select Case InStr(myrst.Fie lds("Connect"), _
"SomeServerName ")
Case 0
Me.Detail.BackC olor = -2147483633
Case Else
Me.Detail.BackC olor = 16744448
End Select
End If
myrst.Close
Set myrst = Nothing
Set mydb = Nothing

Obviously, you'll want to adjust the "SomeBackendTab le" and
"SomeServerName " to be a table and server in your organization, as
well as setting the BackColors to be something someone would actually
_want_ to use!


On 1 Dec 2005 12:35:32 -0800, "Hank" <ha********@aol .com> wrote:
Where I need help is changing the backgound color of all
forms though some itterative method when a new color is selected. My
first (dumb) idea was to have a function on each form that looked up
the color from the Configuration Table. Nahhhh.
I'm using Access 2000.

--
Drive C: Error. (A)bort (R)etry (S)mack The Darned Thing

Dec 1 '05 #7

"Hank" <ha********@aol .com> schreef in bericht news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Lyle,
Thanks for the keen observations about my boss. ;-)

Actually his reasons are pretty good. We have the same
database code installed at two different geographical locations but
with two different bckends. Sometimes he wants to have them both open
at the same time.


Why not use a nice picture of the geografical location (CountryMap?) as background for all the forms?
(Depends on the backend of course...)

Sub PictureInAllFor ms() 'just adapted this, not tested ...
Dim db As Database
Dim cnt As Container
Dim doc As Document
Dim strForm As String
Dim frm As Form

Set db = CurrentDb()
For Each cnt In db.Containers
If cnt.Name = "Forms" Then
For Each doc In cnt.Documents
strForm = doc.Name
DoCmd.OpenForm strForm, acDesign
Set frm = Forms(strForm)
'frm.PictureTil ing = True 'depends if you need this. If so you need it only once
frm.Picture = "C:\Program Files\Microsoft Office2000\Offi ce\Bitmaps\MyNi ce.gif"
DoCmd.Close acForm, strForm, acSaveYes
Next doc
End If
Set db = Nothing
Set cnt = Nothing
Set doc = Nothing
Set frm = Nothing
End Sub

Arno R

Dec 2 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
7203
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
3
1342
by: Tim | last post by:
Hi, I have have a program containing two forms that are open at the same time. The main form updates the second when the user enters input by adding a control to it. My problem is that when the second form (which is in the backgroud) is updated it suddenly jumps to the top of the z-order although it does not have focus. Is there any way...
10
3129
by: Sarah Smith | last post by:
Hello, I am a bit of a newbie to VB.NET, but not totally new. I took the plunge recently and decided (along with my colleagues), to try to convert/port a VB6 client/server app to .Net. (I'm not using any upgrade tools, I'm just re-writing). I have be learning/testing .net with SDI type forms and now I'm actually working on the...
3
2111
by: Ryan Liu | last post by:
I have an thread keep running at the backgroud, if it receive an message from network, it will pop up an chat form and show the message in the chat form. Since this chat form in not pop up by main thread associated with main form, to make this chat form visible, I use Application.Run(chatForm) to make it work. But seems then this will...
1
1869
by: Demi | last post by:
I want to be able to define standard colors in a base form, then have child forms use those values instead of standard colors. Ex in my base form I want to do this: Color myColor = System.Drawing.SystemColors.Control; Then in my child form in the designer, I want to be able to enter "myColor" in the BackColor property.
1
1611
by: Cylix | last post by:
I have a form with a irregular background image, let say a circle. I would like the form shows and that fade out and close slowly. I have already done the fade out part by the timmer to set the form opacity. However, I set the transparent key of the form be white in color, when the form start to fade out, The white part of the form is not...
10
3186
by: Michael B. Trausch | last post by:
Alright... I am attempting to find a way to parse ANSI text from a telnet application. However, I am experiencing a bit of trouble. What I want to do is have all ANSI sequences _removed_ from the output, save for those that manage color codes or text presentation (in short, the ones that are ESChttp://fd0man.theunixplace.com/Tmud.tar which...
5
27544
by: Michael R | last post by:
Searching the net I've found a simple technique to add row numbers and alternate colors (for the even and the uneven row) to a continuous form. 1st step: Create a textbox, send it to background and select the first color. .ControlSouce =fRowNum(False) .Name = RowNum 2nd step: Add the following function to the form module: (for row...
2
2738
by: woodey2002 | last post by:
Hi Guys and thanks for your time. I have a search form for my database that allows users to select multiple criteria from multi select list boxes. I successfully integrated a multi select listbox for users to select and search for counties. On the same page however I would like to integrate a similar multiselect box for nationality. I...
0
7697
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6283
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.