Results 1 to 8 of 8
  1. #1
    alhas is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2011
    Posts
    7

    Newbie VBA question (conditional formatting)


    Excuse the real newbie question, but:

    I'd like to set the background colour of a text field using VBA. (ie. (colour dependant on what's entered). 'Fraid I barely know where to start.

    Help, please?!

    Thanks

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Is this in a form control or a table itself? If you mean the table when opened in datasheet view, then there is no such thing. If a textbox on a form, then I believe Me.TxtBoxName.BackColor property should work out for you.

  3. #3
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936

  4. #4
    alhas is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2011
    Posts
    7
    Thanks very much for your replies. I've taken a look, and had a further think about what I'm trying to achieve. And I think it's not quite as per my initial post. :/

    I have a form, on which I have three fields (let's call them field1, field2 and field3). field3 is a combo-box, with five options (let's call them option1, option2, option3, option4, option5). I'm wondering whether, if I use a text field (field4) as a background to (all together) field1, field2 and field3, I can set the background to turn black when option5 is chosen.

    If I can get the above functionality to work as required on this particular form, I'd like to apply it to some other forms.

    Again, sorry for the completely newbie nature of my query. I'd be very grateful for any help offered. Thank you.

  5. #5
    alhas is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2011
    Posts
    7
    mmm, I'm still not making any progress with this. :/ Can't be that difficult, can it

  6. #6
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Use the rectangle control to make background colors. Draw it the size you want to include all the fields you want. Use this in your code to change the color. Make sure to send it to the back.

    In the AfterUpdate event of the field in question: if field="xxx" then rectangle.backgroundcolor="#111111" else... etc

  7. #7
    alhas is offline Novice
    Windows Vista Access 2007
    Join Date
    Aug 2011
    Posts
    7
    Thanks, I must confess I hadn't thougt of using 'rectangle'. However, I think as I'm v new to VBA, I'm making other mistakes, WHATEVER methid I try. Excuse my VBA ignornace, but could you provide the entire block of code I need to use, please? Thank you very much.

  8. #8
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    In the AfterUpdate event of field3

    If me!field3.column(n) = "x" then
    (note - columns start from 0 so the first column is number 0; column 0 is the default so you can leave it out)

    me!rectangle.backcolor="#111111"

    else

    me!rectangle.backcolor="#222222"

    endif

    Note - layout the code as per your own way - tabbing, etc
    Note - you can also use me!rectangle.visible=true(false)
    Note - remember to do the Send to Back for the rectangle so that you can see the text fields

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Conditional Formatting
    By Paul H in forum Reports
    Replies: 3
    Last Post: 11-07-2011, 11:59 AM
  2. Conditional Formatting
    By Desstro in forum Programming
    Replies: 3
    Last Post: 12-01-2010, 09:52 PM
  3. conditional formatting right(..)
    By bbeernaert in forum Access
    Replies: 3
    Last Post: 08-25-2010, 12:33 AM
  4. Conditional Formatting
    By cevatyildiz in forum Forms
    Replies: 8
    Last Post: 04-30-2010, 12:01 PM
  5. Conditional formatting
    By ylivne in forum Reports
    Replies: 1
    Last Post: 07-12-2009, 06:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums