Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821

    If Control Value is Modified - Format background

    Hi

    Is it possible to make the background of a Control change Colour if the value is changed by the User?



    Any help appreciated

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Compare .Text with .Value?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi Welshgasman

    How would I do this?

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Just guessing, but just compare if not equal on exit of control?
    You also have an .OldValue I believe?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi

    So On exit of Control Compare .OldValue to ,CurrentValue

    My VB Skills are minimal so how would the Syntax be for this?

  6. #6
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Let's make sure the control is bound first? IIRC, an unbound control has no OldValue.
    However if bound, when the form reloads the new value would still be there but whatever you did to highlight that will be gone.
    And what does "changed" mean? Any alteration even when just typing? Or only if an edit has been saved? If the latter and you want it to be permanent you'll have to have an Updated field in the table, and this would only mean it was changed from an original saved value. If you change it 5 more times, it will only tell you that the fifth edit is not the original. Perhaps you'd be better off with a history table or field(s)?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by mike60smart View Post
    Hi

    So On exit of Control Compare .OldValue to ,CurrentValue

    My VB Skills are minimal so how would the Syntax be for this?
    Come on Mike!,

    You have over 300 posts here, over 13K in UA, and over 600 in AWF and you cannot write a simple IF statement?

    You also have to take into account what Micron has mentioned plus resetting any controls when you change record.?

    https://docs.microsoft.com/en-us/off...lse-statements
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  8. #8
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi Welshgasman

    You are right I do know how to write an If statement.

    The only problem is I don't know how to apply an If statement to this process.

    The Subform is a Continuous Form with all Controls Bound and all I want to happen is for just the 1 Control in a specific Record to change colour when the user changes the specific Controls value.

    Is it possible?

  9. #9
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by mike60smart View Post
    Hi Welshgasman

    You are right I do know how to write an If statement.

    The only problem is I don't know how to apply an If statement to this process.

    The Subform is a Continuous Form with all Controls Bound and all I want to happen is for just the 1 Control in a specific Record to change colour when the user changes the specific Controls value.

    Is it possible?
    I have not used continuous forms much, but I believe as long as the controls are bound, each record is treated individually, if not, then one change affects all the records.

    However there is no better way than trying it out?, it is hardly a lot of code?
    Took me a few minutes, but I did the test on a main form control.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  10. #10
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi

    I tried the following in the ONChange Event of the Control:-

    Me.PO_Part_DueDate.BackColor = vbRed

    It works but it changes all of the Records not just the record selected?

  11. #11
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    There is only one of any type of control in the set of controls that are continuous. The rest of them are instances of the control. Change a design property of one and you do it to all. With cf forms, the only way to affect one and not another instance is conditional formatting.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  12. #12
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi Micron

    What would be the Expression to trigger the Background Colour Change on a specific Control?

    Is it possible to use an If statement ? Something Like If [ControlName].Value Changes ?

  13. #13
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Have never tried (that I can recall). Perhaps in the after update event of the control, something like
    If Me.controlName.OldValue <> Me.controlName Then
    use code to modify conditional format property

    perhaps start with
    https://docs.microsoft.com/en-us/arc...ccess-with-vba

    or
    https://docs.microsoft.com/en-us/off...rmatconditions
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,821
    Hi Micron

    Tried the following in the AfterUpdate of the Control but nothing happens:-

    Code:
    Private Sub PO_Part_DueDate_AfterUpdate()
    
    
    10        On Error GoTo PO_Part_DueDate_AfterUpdate_Error
    20    If Me.PO_Part_DueDate <> Me.PO_Part_DueDate Then
    30    Me.PO_Part_DueDate.BackColor = vbRed
    40    End If
              
    50        On Error GoTo 0
    60        Exit Sub
    
    
    PO_Part_DueDate_AfterUpdate_Error:
    
    
    70        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure PO_Part_DueDate_AfterUpdate, line " & Erl & "."
    
    
    End Sub

  15. #15
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Of course nothing happens.
    The If line will never be true so the following line (30) is never run.
    Try reading Micron's post again. That at least has a chance of working!
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 02-24-2019, 05:18 PM
  2. Replies: 3
    Last Post: 01-26-2018, 03:25 AM
  3. Replies: 5
    Last Post: 01-04-2014, 02:29 PM
  4. Tab Control Background
    By redbull in forum Forms
    Replies: 1
    Last Post: 05-25-2012, 02:13 PM
  5. Background Format
    By maysamab in forum Reports
    Replies: 7
    Last Post: 04-06-2009, 10:38 AM

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