Results 1 to 6 of 6
  • Thread Tools
  1. Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Conditional Form Background (VBA Access 2003)

    Hi everyone.

    I was wondering if it's possible for the background of a form to change depending on the value of a control... i.e. if the value is null, then a colour, but if any other value or name etc, then another colour?

    Cheers

    Thom

  2. Subscribe to our Windows Secrets Newsletter - It's Free!

    Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Re: Conditional Form Background (VBA Access 2003)

    What type of form is it? A single form, a continuous form or a datasheet form?

  4. Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Conditional Form Background (VBA Access 2003)

    Hi Hans.

    It's just a single form.

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

    Re: Conditional Form Background (VBA Access 2003)

    Let's say that the control is named txtSomething. You can change the background color of the Detail section in the After Update event of txtSomething (for if the user enters a value or clears it) and in the On Current event of the form (for if the user moves to another record):

    Private Sub ColorDetail()
    If IsNull(Me.txtSomething) Then
    Me.Details.BackColor = vbButtonFace
    Else
    Me.Details.BackColor = vbInfoBackground
    End If
    End Sub

    Private Sub Form_Current()
    Call ColorDetail
    End Sub

    Private Sub txtSomething_AfterUpdate()
    Call ColorDetail
    End Sub

    You can replace vbButtonFace and vbInfoBackgound with other colors, either a symbolic constant such as vbRed, or an RGB value such as RGB(255, 255, 224).

  6. Star Lounger
    Join Date
    Nov 2005
    Location
    London, Gtr London, United Kingdom
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Conditional Form Background (VBA Access 2003)

    This is really helpful Hans. Many thanks

    one last quick question, how would I adapt if I were wanting to apply it to a continuous form?

  7. Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 13 Times in 13 Posts

    Re: Conditional Form Background (VBA Access 2003)

    In a continuous form, it's entirely different. The only items that can change formatting by record in a continuous form are controls (such as text boxes) bound to fields in the record source.

    The database attached to <post#=382,292>post 382,292</post#> demonstrates several ways to highlight records in a continuous form.

Posting Permissions

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