We're aware that some users are experiencing technical issues which the team are working to resolve. See the Community Noticeboard for more info. Thank you for your patience.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

Access 2003 - conditionally format form background color?

Options
_Andy_
_Andy_ Posts: 11,150 Forumite
Hi

Is it possible to conditionally format the background color of a form according to what value a drop-down list field is? Or is there some kind of work around?

For the form I'm designing there is a drop-down field which the user can either choose 'East' or 'South East' from.
Ideally I'd like the background color to then change (e.g. if they select 'East' it goes blue, or 'South East' red, etc.)
The idea being that when we're viewing entries in form view it's easier to see straight away what region they're in.

Cheers for any help

Andy

Comments

  • loudcox
    loudcox Posts: 179 Forumite
    OK, you need to use some VBA.... If you don't know VBA, then PM me and I can guide you through implementing this.

    STEP 1 - The update code
    Private Sub SetFormColour()
    
    Dim FormColour As Variant
    
    Select Case [Region]
        Case "South"
            FormColour = vbRed
        Case "East"
            FormColour = vbGreen
        Case Else
            FormColour = -2147483633 'this is the default colour
    End Select
    
    Me.Detail.BackColor = FormColour
    Me.FormHeader.BackColor = FormColour
    Me.FormFooter.BackColor = FormColour
    
    End Sub
    


    STEP 2 - Calling this when things happen (such as changing the value or scrolling to a record). The example below calls the function whenever the dropdown is used to change the region.
    Private Sub Region_Change()
        SetFormColour
    End Sub
    
    [SIZE=-1]te audire non possum. musa sapientum fixa est in aure.[/SIZE]
  • _Andy_
    _Andy_ Posts: 11,150 Forumite
    Awesome, thanks for that - will give it a go tomorrow. Trying to build up my VBA knowledge so it's all good.
  • loudcox
    loudcox Posts: 179 Forumite
    Cool. Probably the only other point at which you want to call the function is the OnCurrent event for the form.

    Good luck
    m
    [SIZE=-1]te audire non possum. musa sapientum fixa est in aure.[/SIZE]
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 351K Banking & Borrowing
  • 253.1K Reduce Debt & Boost Income
  • 453.6K Spending & Discounts
  • 244K Work, Benefits & Business
  • 598.8K Mortgages, Homes & Bills
  • 176.9K Life & Family
  • 257.3K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.1K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.