Results 1 to 12 of 12
  1. #1
    Star Lounger
    Join Date
    Mar 2003
    Location
    Summerville, South Carolina, USA
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic Color Changes (Access 2000)

    I have a bunch of forms that need to change back ground colors and label colors every month. I have been trying to write a module that I can call to so when I what to change the color, I just change it in the module and my form and labels change. Can anyone help me? It is probably easy for you more experienced programmers. Thanks.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Dynamic Color Changes (Access 2000)

    I don't really understand why you would want to do this. Colors on forms are tricky because different machines and different monitors will render them differently. What's your purpose and how many colors are you talking about?
    Charlotte

  3. #3
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Richland, Washington, USA
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic Color Changes (Access 2000)

    Charlotte's advice is, of course, worth considering.

    Nonetheless, if you want to change colors you need to include a statement like
    <font face="Georgia">
    Me.Section("Detail").BackColor = RGB(rrr, ggg, bbb)
    </font face=georgia>
    in your Form_Open() event. (rrr, ggg, and bbb are values from 0 to 255 which together specify the color mix you want.) If you have other sections on the form (e.g., header and footer), you'll have to set those too. If you have controls with solid backgrounds that you want to match the form's background, they'll have to be set, too (e.g., <font face="Georgia">Me!MyControl.BackColor = RGB(rrr, ggg, bbb)</font face=georgia>).

    If you want to get snazzy, you can "calculate" the color based on the current month; e.g.,
    <font face="Georgia">
    intMonth = Month(Date)
    lngColor = RGB(20 * intMonth, 20 * intMonth, 255)
    Me.Section("Detail").BackColor = lngColor
    .
    .
    .
    </font face=georgia>
    or use an array with your 12 colors and use the current month, <font face="Georgia">Month(Date)</font face=georgia>, to index the array...

    Hope this helps.

  4. #4
    Star Lounger
    Join Date
    Mar 2003
    Location
    Summerville, South Carolina, USA
    Posts
    66
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic Color Changes (Access 2000)

    I guess it is something on my users' wish list. They want each month (or each quarter) to have a new color scheme. So the colors would be detail (or header and footer) backcolor, control font color and control backcolor. When creating a new form, I would like to call to an outside function that already defines my colors. I know it is a wish list and that is may not show the same on each persons computer, but I thought I would give it a try. I know how to create the code within each form, but I want the variable part to be public, so I only have to change it one place not on each form. i hope I am making sense. Thanks

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dynamic Color Changes (Access 2000)

    You might use this function as a starting point. Put it in a standard module. It will apply a quarterly color scheme; you can adapt it to use a monthly color scheme if you like, and you can modify the colors of course - I chose pretty disgusting ones.

    Public Function ChangeColors(frm As Form)
    Dim arrColors(0 To 3, 0 To 3) As Long
    Dim lngQuarter As Long
    Dim ctl As Control
    lngQuarter = (Month(Date) - 1) 3
    arrColors(0, 0) = RGB(224, 224, 224)
    arrColors(0, 1) = RGB(255, 224, 224)
    arrColors(0, 2) = RGB(224, 224, 255)
    arrColors(0, 3) = RGB(0, 0, 0)
    arrColors(1, 0) = RGB(64, 64, 64)
    arrColors(1, 1) = RGB(0, 0, 0)
    arrColors(1, 2) = RGB(64, 128, 64)
    arrColors(1, 3) = RGB(255, 224, 255)
    arrColors(2, 0) = RGB(224, 255, 224)
    arrColors(2, 1) = RGB(255, 192, 224)
    arrColors(2, 2) = RGB(255, 255, 0)
    arrColors(2, 3) = RGB(128, 0, 0)
    arrColors(3, 0) = RGB(224, 224, 0)
    arrColors(3, 1) = RGB(255, 0, 224)
    arrColors(3, 2) = RGB(192, 224, 255)
    arrColors(3, 3) = RGB(0, 0, 128)
    With frm
    .Section(acHeader).BackColor = arrColors(lngQuarter, 0)
    .Section(acDetail).BackColor = arrColors(lngQuarter, 1)
    .Section(acFooter).BackColor = arrColors(lngQuarter, 0)
    For Each ctl In .Controls
    If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Then
    ctl.BackColor = arrColors(lngQuarter, 2)
    ctl.ForeColor = arrColors(lngQuarter, 3)
    End If
    Next ctl
    End With
    Set ctl = Nothing
    End Function

    If you want to apply the color schemes to a form, open the form in design view and activate the Event tab of the Properties window. If the On Load event is blank, enter the following expression directly into the box for the On Load event:

    =ChangeColors([Form])

    If there is already an event procedure, click the ... to the right of the dropdown arrow in the On Load event. Insert the following line into the event procedure:

    ChangeColors Me

  6. #6
    Silver Lounger GARYPSWANSON's Avatar
    Join Date
    Aug 2001
    Location
    Frederick, Maryland, USA
    Posts
    1,788
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Re: Dynamic Color Changes (Access 2000)

    ... you could just hand out a pack of crayons to everyone... <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> <img src=/S/dizzy.gif border=0 alt=dizzy width=15 height=15> <img src=/S/flee.gif border=0 alt=flee width=25 height=25>
    Regards,

    Gary
    (It's been a while!)

  7. #7
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic Color Changes (Access 2000)

    If you have a combo box on a form, with its RowSourceType set to Value List, how can you change its font colour depending on what item you select from the combo's drop-down list?
    I've tried, e.g.,
    <pre>Private Sub Priory_AfterUpdate()
    If Priory = "Normale" Then
    Priory.ForeColor = vbBlack
    Else
    Priory.ForeColor = vbRed
    End If
    End Sub</pre>

    where Priory is the name of the combo but no matter what I choose on the list, the text colour stays black.

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dynamic Color Changes (Access 2000)

    You don't need code for that, you can use conditional formatting.

  9. #9
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic Color Changes (Access 2000)

    I'm afraid I've already used up the three conditions available for the combo box <img src=/S/blush.gif border=0 alt=blush width=15 height=15>

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dynamic Color Changes (Access 2000)

    It helps if you provide relevant information from the start. The conditional formatting is why your code doesn't work. You'll have to remove all conditional formatting from the combo box, and do it *all* in code.

  11. #11
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Dynamic Color Changes (Access 2000)

    Thank you Hans, wouldn't it be possible to use the Modify method of the FormatCondition object, like I'm trying to do in the AfterUpdate event for the Priory combo box in the FrmMag subform, in order to take into account the additional condition that if the user selects "Emergenza" in the Priory combo box, its text turns red?
    Attached Files Attached Files

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Dynamic Color Changes (Access 2000)

    No, that won't work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •