Results 1 to 10 of 10
  1. #1
    Sarah88 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    3

    Unhappy VBA Conditional formatting alternative.

    Hi All


    I am very new to access and have a bit of experience with excel and have ran into a problem that I am hoping someone out there will be kind enough to give me an answer to. I was working on my first database with access and I thought it would be nice to use conditional formatting to change the cell color in my DB when I entered one of three possible responses; Yes, No, N/A to the corresponding colors Green, Red, Orange. I was able to accomplish this with conditional formatting however I was horrified after spending several hours getting all my conditional formatting set up to notice that it had stopped working for the last six columns. Apparently there is a limit on how many conditional formats you can have on one table so my question is there a way to change the cell color based on the the three possible responses; Yes, No, N/A to the corresponding colors in order Green, Red, Orange using VBA.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    How many textboxes are you doing this with?

    If form is not in Datasheet or Continuous view, use VBA to set control properties.

    If this is a report, try VBA in the OnFormat event. Supposed to work but I am not having luck with it right now.
    Last edited by June7; 08-10-2014 at 01:14 PM.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Example:
    If (Me.SomeField) = "SomeValue" Then
    Me.SomeControl) = vbRed
    ElseIf (Me.Somefield) = "Somevalue" Then
    (Me.SomeControl) = vbGreen
    ElseIf (Me.SomeControl) = "SomeValue" Then
    (Me.SomeControl) = vbOrange
    End If
    HTH

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    We really need to know what type of Form we're dealing with, here! The use of the term 'columns' makes it sound suspiciously like you're talking about a Datasheet View Form, in which your only real option is using Conditional Formatting off of the Ribbon. As June7 suggested, you can only use VBA code for this kind of formatting on a Single View Form.

    I've never heard of limitations on the number of Controls that were being used with CF, but how many Fields are we actually talking about, here?

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    Sarah88 is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Aug 2014
    Posts
    3
    Thank you all for replying. to answer question yes we definitely are talking about a Datasheet View Form here, but I am not sure why I can't use something like Burrina suggested. I have looked at the conditional formatting for the other six fields and they appear as ' Value = ""yes"" ' there is that extra set of quotes around the "yes" so I guess I have hit the conditional formatting limit. As for the number of fields well its 40 I want to apply this Yes,No,N/A format to. Surely there must be away to accomplish this

    Thank you for taking the time to reply

  6. #6
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by Sarah88 View Post

    ...yes we definitely are talking about a Datasheet View Form...

    ...I am not sure why I can't use something like Burrina suggested...
    Because it is a Datasheet View Form and you cannot use VBA code to do formatting that effects the appearance of Controls in Datasheet View Forms or Continuous View Forms! In these types of Forms the formatting of ControlA, on the Current Record, will be the the formatting of ControlA, on the All Records. On these types of Forms you can only use Conditional Formatting off of the Ribbon to accomplish this.

    Why is there an extra set of Double Quotes around the yes? That may be the culprit; instead of looking for Yes in the Control, the Access Gnomes may be looking for "Yes".

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    You would need an additional counter for each record and refer to it with OpenArgs, maybe this would work, have not tried it myself!
    What say you Missingling ? Would that work?

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Quote Originally Posted by burrina View Post
    You would need an additional counter for each record and refer to it with OpenArgs, maybe this would work, have not tried it myself!
    What say you Missingling ? Would that work?
    I can honestly say that I have absolutely no idea what you're talking about! What would having an additional counter for each record and referring to it with OpenArgs have to do with the problem at hand? Once again, this is a Datasheet View Form, and any formatting that changes the appearance of a Control, on this type of Form, has to be done with Conditional Formatting, not VBA code...period.
    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  9. #9
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    http://www.lebans.com/conditionalformatting.htm Says it can be done! Have not tried it myself.

  10. #10
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    The Lebans hacks, neat as they are, are a very complicated and only apply to highlighting the current row or alternate rows for these types of Forms; they do not apply to this problem!
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Conditional formatting
    By keiath in forum Forms
    Replies: 28
    Last Post: 01-27-2014, 08:36 AM
  2. Replies: 6
    Last Post: 05-26-2013, 09:10 PM
  3. Conditional Formatting
    By ccordner in forum Reports
    Replies: 6
    Last Post: 01-09-2012, 04:12 PM
  4. Conditional Formatting
    By pkstormy in forum Code Repository
    Replies: 0
    Last Post: 08-30-2010, 09:31 PM
  5. Conditional Formatting
    By cevatyildiz in forum Forms
    Replies: 8
    Last Post: 04-30-2010, 12:01 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