Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Join Date
    Feb 2008
    Posts
    10

    Unanswered: BackColor Problem

    I have a Form (Single Form) that contains 12 unbound Labels one for each month of the year. These have names as follows:
    chJan, chFeb, chMar and so on.

    I have written some code that changes the BackColor property value of the labels. This code makes use of two Combo boxes presented to the user. The first contains the 12 month choice this gets the month. The second Combo Box cointains a list of 8 strings each of these strings has been assigned to an RGB number.

    When the second combo Upadates the code is executed

    This works perfectly, the problem is it changes the Back Color on all records.

    I need to be able to set each record to different BackColor for different labels and then keep those colours independent of what other colours other labels on other records might have. At the moment if I change a color in record 1 it will also change to the same color in all the other records.

    Here is the code


    Code:

    Private Sub DropList_AfterUpdate()

    Dim lngBlank As Long
    Dim lngFlowers As Long
    Dim lngSeedPod As Long
    Dim lngFruit_Berries As Long
    Dim lngAutumnColour As Long
    Dim lngCatkins As Long
    Dim lngDecideuous As Long
    Dim lngCones As Long


    lngBlank = RGB(255, 250, 250)
    lngFlowers = RGB(255, 0, 0)
    lngSeedPod = RGB(153, 51, 0)
    lngFruit_Berries = RGB(153, 204, 0)
    lngAutumnColour = RGB(51, 153, 102)
    lngCatkins = RGB(128, 0, 128)
    lngDecideuous = RGB(0, 255, 0)
    lngCones = RGB(255, 255, 128)

    Dim dropMth
    dropMth = dropMonth.Value

    Dim dropStr
    dropStr = DropList.Value

    Select Case dropStr
    Case "Blank"
    Forms!frmAngiospermae!("ch" & dropMonth).BackColor = lngBlank
    DoCmd.Close
    Case "Flowers"
    Forms!frmAngiospermae!("ch" & dropMonth).BackColor = lngFlowers
    DoCmd.Close
    Case "Seed Pod"
    Forms!frmAngiospermae!("ch" & dropMonth).BackColor = lngSeedPod
    DoCmd.Close
    Case "Fruit and Berries"
    Forms!frmAngiospermae!("ch" & dropMonth).BackColor = lngFruit_Berries
    DoCmd.Close
    Case "Catkins"
    Forms!frmAngiospermae!("ch" & dropMonth).BackColor = lngCatkins
    DoCmd.Close
    Case "Autumn Colour"
    Forms!frmAngiospermae!("ch" & dropMonth).BackColor = lngAutumnColour
    DoCmd.Close
    Case "Decideuous"
    Forms!frmAngiospermae!("ch" & dropMonth).BackColor = lngDecideuous
    DoCmd.Close
    Case "Cones"
    Forms!frmAngiospermae!("ch" & dropMonth).BackColor = lngCones
    DoCmd.Close

    End Select


    End Sub

    ViRi

    --------------------------------------------------------------------------------

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if you are using a 'single form' then you can do what you want
    if you are using a 'continuous form' then you cannot do what you want to do. Its a design limitation in Access.

    you may be able to do what you want using conditional formatting, but I doubt it will work on 12 values.. you may need to be a bit creative.

  3. #3
    Join Date
    Feb 2008
    Posts
    10
    I tried it with conditonal formatting getting the same problem changes all records instead of only the current record even though I'm on single Form

    ViRi

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Regarding continous forms (although probably not applicable with your question)...

    There's an example in the code bank which shows some things you can do (like highlighting the selected record) for a continuous form. There are limitations with continuous forms but there are also some workarounds.

    http://www.dbforums.com/showpost.php...6&postcount=39

    This probably isn't what you're looking for but it's worth looking at to see how to highlight the current record on a continuous form if that's what you have.
    Last edited by pkstormy; 02-17-08 at 20:03.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Quote Originally Posted by ViRi
    I tried it with conditonal formatting getting the same problem changes all records instead of only the current record even though I'm on single Form

    ViRi
    if there are multiple rows/records being displayed then your form is designed for continuous forms, as opposed to a single record/row. You cannot change the background colour of controls for individual records on continuous forms. As Paul (PK stormy) says there are things you can do as workarounds but it isn't going to do exactly what you want.

  6. #6
    Join Date
    Feb 2008
    Posts
    10
    So I should not waste anymore time on this because it will not work period. Maybe its a good idea for me to post my DB to you can look at it, please let me know.

    ViRi

  7. #7
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Almost everything can be done several ways. It sounds like the approach you are taking may not work in Access. But if you explained what you are trying to convey to the user with the different colors, then maybe someone can suggest an alternate approach.

  8. #8
    Join Date
    Feb 2008
    Posts
    10
    This is a very simple DB about Trees. It displays text and pictures about the trees. Each tree will present different set of real life properties or attributes at the different months of the year. To depict this I have eight colours assigned to the attributes and a colour key is presented on the Form. So all the user has to do is look at the colour key and pull that value from a combobox which on update will trigger the code

    ViRi

  9. #9
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Interesting - if you want to zip it and upload it (removing confidential information), we might be able to offer some solutions/workarounds for what you're trying to do.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  10. #10
    Join Date
    Feb 2008
    Posts
    10
    Ok here is the DB as it stands

    ViRi
    Attached Files Attached Files

  11. #11
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    If you want each record on a singleform to show specific colours, those colours must be stored in the fields along with the tree details. Then you can paint labels and whatnot with the colours stored in the fields when you move from record to record (On Current).
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  12. #12
    Join Date
    Feb 2008
    Posts
    10
    Thanks I'll try that but will that change the default BackColor as if you did it manually on design mode.

    ViRi

  13. #13
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Yes.

    The OnCurrent event procedure fires every time you access a record on the form. So you code it to set each object you want to colour to the stored colour(s) in the field(s). From the user's point of view, the screen just looks like you formatted the control yourself... in Design.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  14. #14
    Join Date
    Feb 2008
    Posts
    10
    So you mean I need to have 12 more fields in the Table the Form is derived from. One for each month. And then store the RGB values there?

    Wont that only set the defualt BackColor for all the records to be the same.

    I need to have different colours on each of the 12 month labels for each record. No 2 records can have the same colours.

    I am aquainted with the OnCurrent event but not really quite sure what you mean exactly. Could please expand a bit

    Thanks ViRi

  15. #15
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    So you mean I need to have 12 more fields in the Table the Form is derived from. One for each month. And then store the RGB values there?
    Yes.

    Wont that only set the defualt BackColor for all the records to be the same.
    Well... kinda yes, but when the user moves to a different record, the procedure re-paints the labels, so to the user, the colour changes on each record.

    No 2 records can have the same colours.
    That's a different problem. If the colour configuration has to be unique then it's gonna get trickier.

    I am aquainted with the OnCurrent event but not really quite sure what you mean exactly. Could please expand a bit
    Sure. In the OnCurrent event procedure, you put code like:

    Me.lblJan.BackColor = Me.lngJanColour
    Me.lblFeb.BackColor = Me.lngFebColour
    etc
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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