Results 1 to 9 of 9
  1. #1
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93

    Condition Formatting at After Update event (TextBox)


    Hello.

    I am attempting to write a simple code but could not see why the code will not perform. It just simply does nothing. No error is stated.


    Code:
    Private Sub Text165_AfterUpdate()
    
        Select Case Me.AccredStatus
            Case Is = "Surrendered"
            Me.AccredStatus.BackColor = vbYellow
            Case Is = "Recognized"
            Me.AccredStatus.BackColor = vbYellow
            Case Is = "Suspended"
            Me.AccredStatus.BackColor = vbRed
            Case Is = "Revoked"
            Me.AccredStatus.BackColor = vbRed
            Case Else
            Me.AccredStatus.BackColor = vbBlack
        End Select
        
    End Sub
    Help will be much appreciated!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    Should use Conditional Formatting from the ribbon, not VBA code.
    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
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    I would try a Me.Requery or Me.Reformat or Me.Refresh to repopulate the screen/form with your updates.
    I forget which of these commands should used.

    Give it a try.
    Add the line to be tested after your End Select.


    Just googled and found this. Refresh is the one.
    Good luck.

  4. #4
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    I must apologize for not including a brief explanation of what I would like to come out of this.

    What I would like to see is when the value in the textbox changes to 'Surrendered', the backcolor of the textbox will turn red at the moment when I change records in a form. When I come across a record with 'Accredited', the backcolor will change to black. I want the backcolor change to be done automatically as I cruise through the records in a form.

    How can we make this a possibility?

    Thanks!

  5. #5
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    June7, Thank you for the response.

    I had tried to use the conditional formatting from the ribbon, however, I would then have to keep clicking on the textbox to enforce the conditional formatting application to perform. I want it to do that without having me clicking there all the time...

    Orange, it does not work. Does nothing still. hah

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,601
    You want backcolor of ALL records to be the same depending on the value of the current record?

    You want this to occur as you navigate records as well as when the textbox is edited?

    That involves two events - form Current event and textbox AfterUpdate event.

    It is not necessary to click anything for Conditional Formatting to have effect. It is automatic. I have used it.
    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.

  7. #7
    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 excellenthelp View Post

    ...when the value in the textbox changes to 'Surrendered', the backcolor of the textbox will turn red at the moment when I change records in a form. When I come across a record with 'Accredited', the backcolor will change to black. I want the backcolor change to be done automatically as I cruise through the records in a form....
    Assuming that this is a Single View Form (as it sounds) you can do this with your code current in the Form_Current event. If this is not a Single View Form, you must use Conditional Formatting, as June7 suggested.

    I'm confused, however, because your code currently is in the AfterUpdate event of a Control named Text165 but it refers to a Control named AccredStatus; I would have expected it to be in the AccredStatus_AfterUpdate event.

    Linq ;0)>
    Last edited by Missinglinq; 06-20-2014 at 09:19 AM.

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,847
    Good point Linq!

  9. #9
    excellenthelp is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Mar 2014
    Posts
    93
    Everyone, thank you for the responses! June7 is right- Conditional Formatting is the best way to go (Just as I expected). I had discovered why it was not working in the first place- the Back Style property of the text box was set to 'TRANSPARENT', thus preventing the color from appearing and actually show the changes in color based on the criteria established by the conditional formatting rules.

    So, it is best to leave the Back Style to Normal and just assign the Back Color property the same value as the Back Color of the Form or whatever the text box is placed upon.

    Marking this as SOLVED.

    Thanks again!!!

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

Similar Threads

  1. Replies: 7
    Last Post: 05-08-2014, 10:34 AM
  2. Replies: 9
    Last Post: 11-11-2013, 12:49 PM
  3. Help with Onclick event to refresh textbox.
    By mikeone610 in forum Access
    Replies: 3
    Last Post: 02-07-2013, 03:58 PM
  4. How to call After update event to the textbox
    By pwalter83 in forum Forms
    Replies: 1
    Last Post: 12-20-2011, 11:16 AM
  5. Replies: 1
    Last Post: 12-14-2010, 10:03 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