Results 1 to 8 of 8
  1. #1
    gykiang is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    47

    Public funtion to change backcolor after update of field

    Hi,

    My form contains several text fields with backcolor of beige. My wish is to change the beige color of the field to white after update of the field. The below sample code works well in event procedure for every field (AltINVCL is one of the fields) :

    Private Sub AltINVCL_AfterUpdate()
    If Not IsNull(Me.AltINVCL) Then
    Me.AltINVCL.BackColor = RGB(255, 255, 255)
    Else
    Me.AltINVCL.BackColor = RGB(252, 230, 212)
    End If
    End Sub



    However, this is tedious as the code needs to be modified & repeats for too many fields in VBA. Hence, I'm trying create a short cut by writing a universal code in the Public Function and run the function from the event procedure of each field.

    Can some help and advise how the code in the public function to be written ?

    And also, how do I run this function in desired field with backcolor of beige ?

    Many thanks for any help render.


    Regards
    Kiang

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    This will not work for form in Continuous or Datasheet view.

    Have you considered textbox Conditional Formatting?
    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
    gykiang is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    47
    It is a single form.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    For the generic code, I was going to suggest using ActiveControl but that doesn't have the BackColor property.

    I am not seeing a way to construct a generic procedure.

    Building the code may be tedious but once done, it's done.

    Me.AltINVCL.BackColor = IIf(IsNull(Me.AltNVCL), RGB(252, 230, 212), RGB(255, 255, 255))

    Copy/paste and edit for control names.
    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.

  5. #5
    gykiang is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    47
    Thanks.

    They are bounded fields, so the expression will not work. Guess I have to repeat the code in the event procedure of each field.

  6. #6
    gykiang is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    47
    Thanks June7.

    This code works in event procedure & it more or less simply the long code that I have done previously.

    I didn't know that IIF works in VBA as I thought it is a control used in query.

  7. #7
    gykiang is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    47
    New problem found with code :

    Me.AltINVCL.BackColor = IIf(IsNull(Me.AltNVCL), RGB(252, 230, 212), RGB(255, 255, 255))

    After update of current record with data, the backcolor is changed to white, but the next or new record which is null did not turn back to beige unless I leave the current record blank or null.

    I have inserted the IIf code only in current form because if I repeat the same in the event procedure of After Update , but ambiguous errors appeared after record update.

  8. #8
    gykiang is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Nov 2013
    Posts
    47
    My apology... I got it. Error was caused by replicated code in copy & paste.

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

Similar Threads

  1. Update query to change field data to blank
    By xtrareal22 in forum Queries
    Replies: 3
    Last Post: 12-11-2013, 05:17 PM
  2. FileCopy Funtion
    By dccjr in forum Programming
    Replies: 2
    Last Post: 04-18-2013, 09:04 PM
  3. If/Else If help to Change BackColor
    By SpdRacerX in forum Access
    Replies: 2
    Last Post: 03-20-2012, 10:09 AM
  4. Random Rdn() Funtion Help Please
    By graviz in forum Access
    Replies: 1
    Last Post: 12-09-2009, 11:57 AM
  5. Replies: 1
    Last Post: 10-22-2009, 03:32 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