Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting colours for all forms 1

Status
Not open for further replies.

jedel

Programmer
Jan 11, 2003
430
AU
Hi all,

I'm doing up a simple database for a church and I'm setting up some bells and whistles where they can change the colour of their forms and logo if they wish.

I have all of that set up nicely. Problem I'm having is every form I have to place the following code:

Code:
Dim head, bod, img, fore As String
Dim ctl As Control

head = DLookup("headercolour", "defaultsTBL")
bod = DLookup("bodycolor", "defaultsTBL")
img = DLookup("dblogo", "defaultsTBL")
fore = DLookup("Titles", "defaultsTBL")

Me.FormHeader.BackColor = head
Me.Detail.BackColor = bod
Me.LogoIMG.Picture = img

For Each ctl In Me.Controls
If ctl.Tag = "1" Then
ctl.ForeColor = fore
Else
End If
Next

Me.lblname.Caption = "Logged in as: " & Forms!LoginFRM!txtName

Is there a way where I can set this up as a global function and just call it from the forms? I can do The top half( ie the Dim's and the dlookup lines, but the rest is specific to the forms. It would be nice to be able to do the whole chunk of code as a global function.

Cheers

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Here's a start.

You call this with the form name - eg

Call ColourForm Me.Name

from your own form.

You'll need to tweak the code that changes the colour of the image to the Access form section identifier.

Code:
Public Sub ColourForm (strFormName As String)
Dim head As String, bod As String, img As String, fore As String
Dim ctl As Control

head = DLookup("headercolour", "defaultsTBL")
bod = DLookup("bodycolor", "defaultsTBL")
img = DLookup("dblogo", "defaultsTBL")
fore = DLookup("Titles", "defaultsTBL")

Forms(strFormName).Section(acHeader).BackColor = head
Forms(strFormName).Section(acDetail).BackColor = bod
Forms(strFormName).Section(ac Section Code).LogoIMG.Picture = img ' Need to change to section the picture is located in

For Each ctl In Forms(strFormname).Controls
  If ctl.Tag = "1" Then
    ctl.ForeColor = fore
  Else ' actually not needed as there's no else clause
  End If
Next ctl

Forms(strFormName).lblname.Caption = "Logged in as: " & Forms!LoginFRM!txtName
End Sub

Another way to do this would be just to set the form and controls to use Windows standard colours, so that it will follow whatever they have set in Control Panel.

John
 
Hey Thanks John, That looks pretty good. I'll go in and give it a whirl.

I am interested in your other idea too in setting the clours to match the windows settings. How do you do that?

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Hey John,

Just placed in the code and it works a treat. Was a little confused as to how to call the function, but figured it out in the end.

The "logoIMG" had to be tweaked a little as well because that was a image place holder so it didn't need a section. I also added some other colour choices as well.

Here's the final code for everyone else who might be interested in this.

1. The call for each form is:
Code:
Call ColourForm("FormName")

The code in the genral function is:
Code:
Public Sub ColourForm(strFormName As String)
Dim head As String, bod As String, img As String, fore As String, Btxt As String, Ftxt As String, FBack As String
Dim ctl As Control

head = DLookup("headercolour", "defaultsTBL")
bod = DLookup("bodycolor", "defaultsTBL")
img = DLookup("dblogo", "defaultsTBL")
fore = DLookup("Titles", "defaultsTBL")
Btxt = DLookup("BTitles", "defaultsTBL")
Ftxt = DLookup("FText", "defaultsTBL")
FBack = DLookup("FBack", "defaultsTBL")

Forms(strFormName).Section(acHeader).BackColor = head
Forms(strFormName).Section(acDetail).BackColor = bod
Forms(strFormName).LogoIMG.Picture = img ' Need to change to section the picture is located in

For Each ctl In Forms(strFormName).Controls
    Select Case ctl.Tag
    Case Is = "1"
        ctl.ForeColor = fore
    Case Is = "2"
        ctl.ForeColor = Btxt
    Case Is = "3"
        ctl.ForeColor = Ftxt
        ctl.BackColor = FBack
    End Select

Next ctl

Forms(strFormName).lblname.Caption = "Logged in as: " & Forms!LoginFRM!txtName
End Sub

Thanks again John, Have a star!

Cheers

Dean

-------------------------------------------------------------
"The most overlooked advantage of owning a computer is that if they foul up there's no law against whacking them around a bit."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top