Results 1 to 9 of 9
  1. #1
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128

    Question Referencing Table Field Value to Change Back Color (with if/iif VBA/expression)

    I have a report where some field values will be blank at times. I would like to write an if statement (in VBA or as an expression) to state that if the field is blank, to change the back color of the field value on the report.

    I can't seem to get it to work in either VBA or as an expression. In VBA I get a debugging error as to how I reference the table field value. In an expression (I am not sure how to refer to the back color of a field) I first tested with true returning "Good" and false returning "Bad". Even though the table field value is blank, it returns "Bad". I even tried to include IsNull(""), but this still returns "Bad". Even if I put a value in the table field and refer to that in the expression, it still returns "Bad" instead of "Good".

    Can anyone provide me an example on how this would be done?

    At the moment I don't have a date selection form before the report, but I have a record in the table that shows when switching the report to View mode.

    Thank you!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Why not just use Conditional Formatting?

  3. #3
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128
    Thanks for the reply.

    This looks like what I need, but I still am unsure what I can use in the expression area to state that when the field is blank use the color.

    I tried "" and used Nz without success.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    To begin with, reference the control on the report and not the field in the table. Try something like:
    IIF(Len([YourControl] & "") =0) ... in the conditional format.

  5. #5
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128
    Thanks for the help.

    I tried your expression, but it stated that it had the wrong number of arguments.

  6. #6
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128
    Oddly enough just found a similar post you replied in from 2009: http://www.access-programmers.co.uk/...d.php?t=168241

  7. #7
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128
    I tried your VBA code from the 2009 post as follows:

    If Len(Me.DailyEndDepth & "") = 0 Then
    Me.DailyEndDepth.BackColor = vbBlack
    End If

    When I click View for my report, it gives me a debugging error that states "The expression you entered has a field, control, or property name that Microsoft Access can't find." And it highlights the words I have in red.

  8. #8
    Heatshiver is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2011
    Posts
    128
    Figured it out for the VBA (still not sure what's up with the expression).

    I had been putting it in the Open event of the report, but it needed to be on the Load event.

    Thanks for the help.

  9. #9
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad to hear you got it sorted. The Conditional Format expression is probably:
    IIF( Len(Me.DailyEndDepth & "") = 0,True,False)

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

Similar Threads

  1. Report Back Color formatting
    By RayMilhon in forum Reports
    Replies: 5
    Last Post: 02-07-2012, 03:20 PM
  2. Alternate Back Color not working properly
    By kolarbr in forum Access
    Replies: 7
    Last Post: 08-30-2011, 10:16 AM
  3. Back color update issue
    By GraemeG in forum Programming
    Replies: 3
    Last Post: 03-21-2011, 11:32 AM
  4. Referencing table data in field validation rule
    By toad848 in forum Database Design
    Replies: 3
    Last Post: 03-19-2009, 07:03 AM
  5. Replies: 1
    Last Post: 02-05-2009, 04:53 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